home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / v cisle / htttrack / httrack-3.41-3.exe / {app} / src_win / WinHTTrack / Shell.cpp < prev    next >
C/C++ Source or Header  |  2006-10-01  |  112KB  |  3,041 lines

  1. // Shell.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. // thread windows
  5. #include <process.h>
  6.  
  7. #include "stdafx.h"
  8. #include "Shell.h"
  9. #include "NewProj.h"
  10.  
  11. extern "C" {
  12.   #include "HTTrackInterface.h"
  13. };
  14. //#include "htsbase.h"
  15.  
  16. // Ras
  17. #if USE_RAS 
  18. #include "RasLoad.h"
  19. #endif
  20.  
  21. #include <afxdisp.h>
  22. #include "ras.h"
  23. #include "mmsystem.h"
  24.  
  25. //#include "ShellDoc.h"
  26. //#include "ShellView.h"
  27.  
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33.  
  34. // PATCH-->
  35. // PATCH-->
  36. #include "about.h"
  37. #include "infoend.h"
  38.  
  39. // flag de termination
  40. int termine=0;
  41. int termine_requested=0;
  42. int shell_terminated=0;
  43. int soft_term_requested=0;
  44. FILE* fp_debug=NULL;
  45.  
  46. #include "stdafx.h"
  47. #include "Shell.h"
  48. #include "process.h"
  49. //#include "ShellDoc.h"
  50. //#include "ShellView.h"
  51. //#include "essai.h"
  52. //#include "get.h"
  53. //#include "parameter.h"
  54. extern "C" {
  55.   #include "HTTrackInterface.h"
  56. }
  57. #include "Wid1.h"
  58. #include "trans.h"
  59. #include "InfoUrl.h"
  60. //#include "option.h"
  61. //#include "filter.h"
  62. //#include "wizard.h"
  63. //
  64. #include "maintab.h"
  65. //
  66. #include "MemRegister.h"
  67.  
  68. // LANG
  69. #include "newlang.h"
  70.  
  71.  
  72. // PATCH-->
  73. //#include "wizard2.h"
  74. //#include "WizLinks.h"
  75.  
  76. #include "inprogress.h"
  77.  
  78. #include "SYS\TIMEB.H"
  79.  
  80. // htswrap_add
  81. extern "C" {
  82.   #include "htswrap.h"
  83. };
  84.  
  85. // --- --- --- --- Options --- --- --- ---
  86.  
  87. #define MAX_LEN_INPROGRESS 32
  88.  
  89. // lancement en multithread du shell ET de gethostbyname
  90. #define SHELL_MULTITHREAD 1
  91. //#define HTS_XGMETHOD 2    // 1: AfxBeginThread 2: _beginthread
  92. // --- --- --- --- Options --- --- --- ---
  93. //int INREDRAW_LOCKED=0;      // refresh graphique en cours
  94. //int INFILLMEM_LOCKED=0;     // refresh mΘmoire en cours
  95. int HTTRACK_result=0;
  96. //
  97. CInfoUrl* _Cinprogress_inst=NULL;
  98.  
  99. extern HICON httrack_icon;
  100.  
  101. /* Main splitter frame */
  102. #include "DialogContainer.h"
  103. #include "splitter.h"
  104. extern CSplitterFrame* this_CSplitterFrame;
  105.  
  106. /* Main WizTab frame */
  107. #include "WizTab.h"
  108. extern CWizTab* this_CWizTab;
  109. /* Argh - pas de domodal dans des autres threads ?!?! */
  110. char WIZ_question[1000];
  111. char WIZ_reponse[1000];
  112.  
  113. httrackp *global_opt = NULL;
  114.  
  115. // Fonctionnement des THREADS:
  116. //
  117. // principal ---> robot & refresh data (thread 1)
  118. //           ---> refresh graphique    (thread 2)
  119. //           GO!> boucle gestion domodal() et boutons
  120. // arrΩt: principal demande l'arrΩt (termine_requested)
  121. //        thread1 active termine et que thread2 ait fini de refresher
  122. //        thread2 se termine
  123. //        thread1 retourne 0 α hts_loop
  124. //        le robot termine
  125. //        le thread1 active termine, termine le formulaire et se termine
  126. //        principal ayant quittΘ le formulaire affiche le message de fin
  127.  
  128.  
  129. // htslib.c
  130. extern "C" {
  131.   HTSEXT_API void qsec2str(char *st,TStamp t);
  132. }
  133.  
  134. // construction index gΘnΘral
  135. // void Build_TopIndex();
  136.  
  137. void compute_options() ;
  138. static void StripControls(char * chaine);
  139. void lance(void);
  140. int check_continue(char* pathlog);
  141. int inprogress_refresh();
  142. //int inprogress_refresh_scan();
  143. void Write_profile(CString path,int load_path);
  144. void Read_profile(CString path,int load_path);
  145.  
  146. extern "C" {
  147.   #include "htscore.h"
  148. }
  149.  
  150. CString _HTTRACK_VERSION = HTTRACK_VERSION;
  151.  
  152. CShellOptions* ShellOptions;
  153.  
  154.  
  155. // Fichier tempo
  156. FILE* tmpf=NULL;
  157. MemRegister tmpm;
  158.  
  159. CNewProj* dialog0=NULL;
  160. Wid1* dialog1=NULL;
  161. Ctrans* dialog2=NULL;
  162. //Coption dialog3;
  163. //Cfilter diafiltre;
  164. /*
  165. wizard diawiz;
  166. wizard2 diawiz2;
  167. WizLinks diawiz3;
  168. */
  169. //
  170. CMainTab* maintab=NULL;
  171. CShellApp* CShellApp_app=NULL;
  172.  
  173. #include "infoend.h"
  174. extern Cinfoend* this_Cinfoend;
  175.  
  176.  
  177. // PATCH-->
  178. Cinprogress* inprogress=NULL;
  179.  
  180. // nbre de slides
  181. t_StatsBuffer StatsBuffer[NStatsBuffer];
  182. void* StatsBufferback=NULL;
  183. int StatsBufferback_max=0;
  184. InpInfo SInfo;
  185.  
  186. #if USE_RAS
  187. // Chargement des librairies RAS
  188. CDynamicRAS* LibRas=NULL;
  189. int LibRasUse=0;
  190. //
  191. int connected=0;
  192. int disconnect=0;
  193. int shutdown_pc=0;
  194. HRASCONN conn = NULL;
  195. int has_started=0;
  196. char connected_err[1000]="";
  197. #endif
  198.  
  199. // pour message final
  200. extern char end_mirror_msg[8192];
  201. #include "winhttrack.h"
  202. extern CWinHTTrackApp* this_app;
  203.  
  204.  
  205. // PATCH-->
  206. // PATCH-->
  207. // FIN PATCH
  208.  
  209.  
  210. /////////////////////////////////////////////////////////////////////////////
  211. // CShellApp
  212.  
  213. /*
  214. BEGIN_MESSAGE_MAP(CShellApp, CWinApp)
  215. //{{AFX_MSG_MAP(CShellApp)
  216. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  217. // NOTE - the ClassWizard will add and remove mapping macros here.
  218. //    DO NOT EDIT what you see in these blocks of generated code!
  219. //}}AFX_MSG_MAP
  220. // Standard file based document commands
  221. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  222. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  223. // Standard print setup command
  224. ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  225. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  226. END_MESSAGE_MAP()
  227. */
  228.  
  229. /////////////////////////////////////////////////////////////////////////////
  230. // CShellApp construction
  231.  
  232. CShellApp::CShellApp()
  233. {
  234.   // TODO: add construction code here,
  235.   // Place all significant initialization in InitInstance
  236. }
  237.  
  238. /////////////////////////////////////////////////////////////////////////////
  239. // The one and only CShellApp object
  240.  
  241. //CShellApp theApp;
  242.  
  243. /////////////////////////////////////////////////////////////////////////////
  244. // CShellApp initialization
  245.  
  246. static void __cdecl RunBackMirror( LPVOID pP ) {
  247.   CShellApp_app->init_lance();
  248. }
  249.  
  250. BOOL LaunchMirror() {
  251.   WHTT_LOCK();
  252.   //hts_resetvar();
  253.   WHTT_UNLOCK();
  254.   hts_newthread(RunBackMirror, NULL);
  255.   return 0;
  256. }
  257.  
  258. #if 0
  259. BOOL CShellApp::InitInstance()
  260. {
  261.   CShellApp_app=this;
  262.   termine=termine_requested=shell_terminated=soft_term_requested=0;
  263.   
  264.   // Initialize OLE libraries
  265.   /*
  266.   if (!AfxOleInit())
  267.   {
  268.   AfxMessageBox(LANG(LANG_F1));
  269.   return FALSE;
  270.   }
  271.   AfxEnableControlContainer();
  272.   */
  273.   
  274.   // Fixer localisation dans la base de registre
  275.   //SetRegistryKey("WinHTTrack");
  276.   
  277.   // Standard initialization
  278.   // If you are not using these features and wish to reduce the size
  279.   //  of your final executable, you should remove from the following
  280.   //  the specific initialization routines you do not need.
  281.   /*
  282.   #ifdef _AFXDLL
  283.   Enable3dControls();            // Call this when using MFC in a shared DLL
  284.   #else
  285.   Enable3dControlsStatic();    // Call this when linking to MFC statically
  286.   #endif
  287.   */
  288.   
  289.   // Register the application's document templates.  Document templates
  290.   //  serve as the connection between documents, frame windows and views.
  291.   
  292.   // Change the registry key under which our settings are stored.
  293.   // You should modify this string to be something appropriate
  294.   // such as the name of your company or organization.
  295.   //SetRegistryKey(_T("Local AppWizard-Generated Applications"));
  296.   
  297.   //LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  298.   
  299.   // Register the application's document templates.  Document templates
  300.   //  serve as the connection between documents, frame windows and views.
  301.   
  302.   // Parse command line for standard shell commands, DDE, file open
  303.   /*CCommandLineInfo cmdInfo;
  304.   ParseCommandLine(cmdInfo);
  305.   */
  306.   
  307.   _Cinprogress_inst=NULL;
  308.   
  309.   LibRasUse=0;
  310.   
  311.   /*
  312.   #if USE_RAS
  313.   LibRas=new CDynamicRAS();
  314.   if (LibRas->IsRASLoaded()) 
  315.   LibRasUse=1;
  316.   else
  317.   LibRasUse=0;
  318.   #endif
  319.   */
  320.   
  321.   maintab = new CMainTab("WinHTTrack Website Copier");
  322.   
  323.   // PATCH-->
  324.   // ΘxΘcution..
  325.   init_lance();
  326.   
  327.   delete maintab;
  328.   maintab=NULL;
  329.   
  330.   // PATCH-->
  331.   /*
  332.   // Dispatch commands specified on the command line
  333.   if (!ProcessShellCommand(cmdInfo))
  334.         return FALSE;
  335.     
  336.       // The one and only window has been initialized, so show and update it.
  337.       m_pMainWnd->ShowWindow(SW_SHOW);
  338.       m_pMainWnd->UpdateWindow();
  339.   */  
  340.   
  341.   
  342.   return TRUE;
  343. }
  344. #endif
  345.  
  346. // PATCH-->
  347. // routines diverses
  348.  
  349. char* _SN(LLint n) {
  350.   static char str[256];
  351.   str[0]='\0';
  352.   sprintf(str,LLintP,(LLint)n);        /* 64-bit */
  353.   return str;
  354. }
  355.  
  356. // t existe-t-il comme rΘpertoire?
  357. int dir_check(char* t) {
  358.   int dir;
  359.   FILE* fp=fopen(t,"rb");
  360.   dir=(errno==13);  // is directory
  361.   if (fp) fclose(fp);
  362.   return dir;
  363. }
  364.  
  365. void check_temp(char* t,char* s) {
  366.   if (strlen(s)==0)
  367.     if (dir_check(t))
  368.       strcpybuff(s,t);
  369. }
  370.  
  371.  
  372.  
  373. // PATCH-->
  374. // Routines gestion dials
  375. // PatchΘ pour 100% dials
  376.  
  377.  
  378. void CShellApp::init_lance() {
  379.   hts_init();
  380.   termine=termine_requested=shell_terminated=soft_term_requested=0;
  381.   lance();             // Lancer miroir!
  382.   if (fp_debug) {
  383.     fprintf(fp_debug,"Building top index\r\n");
  384.     fflush(fp_debug);
  385.   }
  386.   Build_TopIndex();
  387. }
  388.  
  389. /* sauver profile */
  390. /* ask: demande confirmation, si cela vaut le coup */
  391. int Save_current_profile(int ask) {
  392.   CString winprofile;
  393.   if (ask) {
  394.     if ((dialog0->GetName().IsEmpty()) && (dialog1->m_urls.IsEmpty()))
  395.       return IDNO;
  396.     int r;
  397.     char msg[256];
  398.     sprintf(msg,"%s?\r\n%s",LANG_SAVEPROJECT,dialog0->GetName());
  399.     if ((r=AfxMessageBox(msg,MB_YESNOCANCEL)) != IDYES)
  400.       return r;
  401.   }
  402.   //
  403.   CWaitCursor wait;
  404.   
  405.   // sauver whtt
  406.   {
  407.     CString st=dialog0->GetBasePath()+dialog0->GetName()+".whtt";
  408.     FILE* fp=fopen(st,"wb");
  409.     if (fp) fclose(fp);
  410.   }
  411.   
  412.   // sauver ini
  413.   winprofile=dialog0->GetPath();
  414.   if (winprofile.GetLength()>0)
  415.     if ((winprofile.Right(1)!="/") && (winprofile.Right(1)!="\\"))
  416.       winprofile+="\\";
  417.     winprofile+="hts-cache\\";
  418.     {
  419.       char tempo[HTS_URLMAXSIZE*2];
  420.       int i;
  421.       strcpybuff(tempo,winprofile);
  422.       for(i=0;i<(int)strlen(tempo);i++)
  423.         if (tempo[i]=='\\')
  424.           tempo[i]='/';              
  425.         structcheck(tempo);
  426.     }
  427.     
  428.     winprofile+="winprofile.ini";
  429.     Write_profile(winprofile,0);
  430.     
  431.     // marquer document comme "sauvΘ"
  432.     if (this_CSplitterFrame)
  433.       this_CSplitterFrame->SetSaved();
  434.     
  435.     return IDYES;
  436. }
  437.  
  438. // reprise possible?
  439. int check_continue(char* pathlog) {
  440.     char catbuff[CATBUFF_SIZE];
  441.     char catbuff2[CATBUFF_SIZE];
  442.     char catbuff3[CATBUFF_SIZE];
  443.   char path_log[256];
  444.   strcpybuff(path_log,pathlog);
  445.   if (strlen(path_log)>0)
  446.     if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  447.       strcatbuff(path_log,"/");
  448.     if (
  449.       fexist(fconcat(catbuff,path_log,"hts-cache/new.zip"))
  450.       ||
  451.       (fexist(fconcat(catbuff2,path_log,"hts-cache/new.dat"))) && (fexist(fconcat(catbuff3,path_log,"hts-cache/new.ndx")))
  452.       ) {  // il existe dΘja un cache prΘcΘdent.. renommer
  453.       //if (fexist(fconcat(path_log,"hts-cache/doit.log"))) {    // un cache est prΘsent
  454.       return 1;
  455.       //}
  456.     }
  457.     if (
  458.       fexist(fconcat(catbuff,path_log,"hts-cache/old.zip"))
  459.       ||
  460.       (fexist(fconcat(catbuff2,path_log,"hts-cache/old.dat"))) && (fexist(fconcat(catbuff3,path_log,"hts-cache/old.ndx")))
  461.       ) {  // il existe dΘja un ancien cache prΘcΘdent.. renommer
  462.       return 1;
  463.     }
  464.     AfxMessageBox(LANG(LANG_F2 /*"There is no cache in the directory indicated\nWinHTTrack can not find any interrupted mirror!"*/),MB_OK+MB_ICONSTOP);
  465.     return 0;
  466. }
  467.  
  468.  
  469. void CShellApp::OptPannel() {
  470.   Write_profile("<mem>",0);       // enregistrer profile dans buffer local
  471.   if (maintab->DoModal()==IDCANCEL) {
  472.     Read_profile("<mem>",0);      // restaurer
  473.   }
  474. }
  475.  
  476.  
  477. #define ADD_MIME_IN_COPT(A) \
  478.   if(strlen(maintab->m_option11.m_ext##A)+strlen(maintab->m_option11.m_mime##A)) { \
  479.   ShellOptions->buff_MIME += "--assume "; \
  480.   ShellOptions->buff_MIME += maintab->m_option11.m_ext##A; \
  481.   ShellOptions->buff_MIME += "="; \
  482.   ShellOptions->buff_MIME += maintab->m_option11.m_mime##A; \
  483.   ShellOptions->buff_MIME += " "; \
  484.   } \
  485.   
  486. // parser maintab et calculer options
  487. void compute_options() { 
  488.   CWaitCursor wait;
  489.   
  490.   /* Effacer options */
  491.   if (ShellOptions != NULL) {
  492.     delete ShellOptions;
  493.     ShellOptions = NULL;
  494.   }
  495.   ShellOptions = new CShellOptions();
  496.   /* Effacer options */
  497.   
  498.   // Mode de miroir
  499.   switch(dialog1->m_todo) {
  500.   case CB_ERR: case 0:
  501.     ShellOptions->choixdeb = "w";
  502.     break;
  503.   case 1:
  504.     ShellOptions->choixdeb = "W";
  505.     break;
  506.   case 2:
  507.     ShellOptions->choixdeb = "g";
  508.     break;
  509.   case 3:
  510.     ShellOptions->choixdeb = "Y";
  511.     break;
  512.   case 4:
  513.     ShellOptions->choixdeb = "!";
  514.     break;
  515.   default:
  516.     if (dialog1->m_todo==dialog1->LAST_ACTION)
  517.       ShellOptions->choixdeb = "i";    // reprise
  518.     else
  519.       ShellOptions->choixdeb = "/";    // reprise cache prioritaire
  520.     break;
  521.   }
  522.   
  523.   // URLS
  524.   ShellOptions->url = dialog1->m_urls;
  525.   StripControls(ShellOptions->url.GetBuffer(0));
  526.   // --- formation du path
  527.   ShellOptions->path = "\"";
  528.   ShellOptions->path += dialog0->GetPath0();
  529.   ShellOptions->path += "\"";
  530.   //ShellOptions->path += ",";
  531.   //ShellOptions->path += "\"";
  532.   //ShellOptions->path += dialog0->GetPath0();
  533.   //ShellOptions->path += "\"";
  534.   
  535.   // filelist
  536.   {
  537.     CString st=dialog1->m_filelist;
  538.     st.TrimLeft();
  539.     st.TrimRight();
  540.     ShellOptions->filelist = st;
  541.   }
  542.   
  543.   // stocker Θtat et hh/mm/ss
  544.   ShellOptions->hh = dialog2->m_hh;
  545.   ShellOptions->mm = dialog2->m_mm;
  546.   ShellOptions->ss = dialog2->m_ss;
  547.   if (ShellOptions->hh.GetLength()) {    // heure
  548.     int x,y,z;
  549.     sscanf(ShellOptions->hh.GetBuffer(0),"%d",&x);
  550.     x=min(max(x,0),23);
  551.     ShellOptions->hh.Format("%d",x);
  552.     //
  553.     sscanf(ShellOptions->mm.GetBuffer(0),"%d",&y);
  554.     y=min(max(y,0),59);
  555.     ShellOptions->mm.Format("%d",y);
  556.     //
  557.     sscanf(ShellOptions->ss.GetBuffer(0),"%d",&z);
  558.     z=min(max(z,0),59);
  559.     ShellOptions->ss.Format("%d",z);
  560.     //
  561.     ShellOptions->waittime = "";
  562.     {
  563.       char str[32];
  564.       ShellOptions->waittime = "#u";
  565.       sprintf(str,"%d",x*3600+y*60+z);
  566.       ShellOptions->waittime += str;
  567.     }
  568.   }
  569.   ShellOptions->_RasString = dialog2->RasString;
  570.   ShellOptions->_dial=dialog2->dial;
  571.   
  572.   if (ShellOptions->choixdeb[0]=='/') {
  573.     ShellOptions->cache = "C1";      // cache prio
  574.   } else {
  575.     if(!maintab->m_option3.m_cache) 
  576.       ShellOptions->cache = "C0"; 
  577.     else 
  578.       ShellOptions->cache = "C2";     // cache non prio 
  579.     //ShellOptions->cache[0]='\0'; 
  580.   }
  581.   
  582.   // ne pas recharger fichiers dΘja pris mais effacΘs
  583.   if(maintab->m_option9.m_norecatch) ShellOptions->norecatch = "%n"; else ShellOptions->norecatch = "";
  584.   
  585.   // proxy
  586.   ShellOptions->proxy = maintab->m_option10.m_proxy;
  587.   ShellOptions->port = maintab->m_option10.m_port;
  588.   if (maintab->m_option10.m_ftpprox) 
  589.     ShellOptions->proxyftp = "%f";
  590.   else
  591.     ShellOptions->proxyftp = "%f0";   
  592.   
  593.   //depth
  594.   ShellOptions->depth = maintab->m_option5.m_depth;
  595.   ShellOptions->extdepth = maintab->m_option5.m_depth2;
  596.   
  597.   if(!maintab->m_option9.m_index) ShellOptions->index = "I0"; else ShellOptions->index = ""; 
  598.   if(!maintab->m_option9.m_index2) ShellOptions->index2 = "%I0"; else ShellOptions->index2 = "%I"; 
  599.   if(maintab->m_option2.m_dos) 
  600.     ShellOptions->dos = "L0"; 
  601.   else if(maintab->m_option2.m_iso9660) 
  602.     ShellOptions->dos = "L2"; 
  603.   else 
  604.     ShellOptions->dos = ""; 
  605.   if(maintab->m_option1.m_testall) ShellOptions->testall = "t"; else ShellOptions->testall = ""; 
  606.   if(maintab->m_option1.m_parseall) ShellOptions->parseall = "%P"; else ShellOptions->parseall = "%P0"; 
  607.   if(maintab->m_option1.m_link) ShellOptions->link = "n"; else ShellOptions->link = ""; 
  608.   if(maintab->m_option1.m_htmlfirst) ShellOptions->htmlfirst = "p7"; else ShellOptions->htmlfirst = ""; 
  609.   if(maintab->m_option2.m_errpage) ShellOptions->errpage = "o0"; else ShellOptions->errpage = ""; 
  610.   if(maintab->m_option2.m_external) ShellOptions->external = "x"; else ShellOptions->external = ""; 
  611.   if(maintab->m_option2.m_nopurge) ShellOptions->nopurge = "X0"; else ShellOptions->nopurge = ""; 
  612.   if(maintab->m_option2.m_hidepwd) ShellOptions->hidepwd = "%x"; else ShellOptions->hidepwd = ""; 
  613.   if(maintab->m_option2.m_hidequery) ShellOptions->hidequery = "%q0"; else ShellOptions->hidequery = ""; 
  614.   
  615.   ShellOptions->robots = "";
  616.   if(maintab->m_option8.m_robots==0) ShellOptions->robots = "s0"; 
  617.   else if(maintab->m_option8.m_robots==1) ShellOptions->robots = "s1"; 
  618.   else if(maintab->m_option8.m_robots==2) ShellOptions->robots = "s2"; 
  619.   
  620.   // cookies,checktype,parsejava
  621.   if(maintab->m_option8.m_cookies==0) ShellOptions->cookies = "b0"; // else ShellOptions->cookies = "b1";
  622.   if (maintab->m_option8.m_checktype>=0)
  623.     ShellOptions->checktype.Format("u%d",maintab->m_option8.m_checktype);
  624.   if(maintab->m_option8.m_parsejava==0) ShellOptions->parsejava = "j0"; // else ShellOptions->cookies = "j1";
  625.   if (maintab->m_option8.m_http10) ShellOptions->http10 = "%h";   // HTTP/1.0 notamment
  626.   if (maintab->m_option8.m_toler)  ShellOptions->toler = "%B";    // tolerent
  627.   if (maintab->m_option8.m_updhack)  ShellOptions->updhack = "%s";    // update hack
  628.   if (maintab->m_option8.m_urlhack)  ShellOptions->urlhack = "%u";    // URL hack
  629.   else                               ShellOptions->urlhack = "%u0";
  630.   
  631.   // store all in cache,logtype
  632.   if(maintab->m_option9.m_Cache2!=0) ShellOptions->Cache2 = "k";
  633.   if(maintab->m_option9.m_logtype==1) ShellOptions->logtype = "z";
  634.   else if(maintab->m_option9.m_logtype==2) ShellOptions->logtype = "Z";
  635.   if (maintab->m_option3.m_windebug) ShellOptions->logtype += "%H";      // debug headers
  636.   
  637.   ShellOptions->build = "";
  638.   if      (maintab->m_option2.m_build==0) ShellOptions->build = "N0";
  639.   else if (maintab->m_option2.m_build==1) ShellOptions->build = "N1";
  640.   else if (maintab->m_option2.m_build==2) ShellOptions->build = "N2";
  641.   else if (maintab->m_option2.m_build==3) ShellOptions->build = "N3";
  642.   else if (maintab->m_option2.m_build==4) ShellOptions->build = "N4";
  643.   else if (maintab->m_option2.m_build==5) ShellOptions->build = "N5";
  644.   else if (maintab->m_option2.m_build==6) ShellOptions->build = "N100";
  645.   else if (maintab->m_option2.m_build==7) ShellOptions->build = "N101";
  646.   else if (maintab->m_option2.m_build==8) ShellOptions->build = "N102";
  647.   else if (maintab->m_option2.m_build==9) ShellOptions->build = "N103";
  648.   else if (maintab->m_option2.m_build==10) ShellOptions->build = "N104";
  649.   else if (maintab->m_option2.m_build==11) ShellOptions->build = "N105";
  650.   else if (maintab->m_option2.m_build==12) ShellOptions->build = "N99";
  651.   else if (maintab->m_option2.m_build==13) ShellOptions->build = "N199";
  652.   else if (maintab->m_option2.m_build==14) {
  653.     ShellOptions->build = "-N \"";
  654.     ShellOptions->build += maintab->m_option2.Bopt.m_BuildString;
  655.     ShellOptions->build += "\"";
  656.   }
  657.   
  658.   ShellOptions->filtre = "";
  659.   if      (maintab->m_option3.m_filter==0) ShellOptions->filtre = "p0";
  660.   else if (maintab->m_option3.m_filter==1) ShellOptions->filtre = "p1";
  661.   else if (maintab->m_option3.m_filter==2) ShellOptions->filtre = "p2";
  662.   else if (maintab->m_option3.m_filter==3) {    /* default */
  663.     if(!maintab->m_option1.m_htmlfirst) ShellOptions->filtre = "p3";
  664.   }
  665.   else if (maintab->m_option3.m_filter==4) ShellOptions->filtre = "p7";
  666.   //
  667.   if      (maintab->m_option3.m_travel==0) ShellOptions->filtre += "S";
  668.   else if (maintab->m_option3.m_travel==1) ShellOptions->filtre += "D";
  669.   else if (maintab->m_option3.m_travel==2) ShellOptions->filtre += "U";
  670.   else if (maintab->m_option3.m_travel==3) ShellOptions->filtre += "B";
  671.   //
  672.   if      (maintab->m_option3.m_travel2==0) ShellOptions->filtre += "a";
  673.   else if (maintab->m_option3.m_travel2==1) ShellOptions->filtre += "d";
  674.   else if (maintab->m_option3.m_travel2==2) ShellOptions->filtre += "l";
  675.   else if (maintab->m_option3.m_travel2==3) ShellOptions->filtre += "e";
  676.   //
  677.   if      (maintab->m_option3.m_travel3==0) ShellOptions->filtre += "K0";
  678.   else if (maintab->m_option3.m_travel3==1) ShellOptions->filtre += "K";
  679.   else if (maintab->m_option3.m_travel3==2) ShellOptions->filtre += "K3";
  680.   else if (maintab->m_option3.m_travel3==3) ShellOptions->filtre += "K4";
  681.  
  682.   if (maintab->m_option9.m_logf) ShellOptions->log = "f2"; else ShellOptions->log = "Q"; 
  683.   
  684.   if(maintab->m_option5.m_sizemax!=""){
  685.     ShellOptions->max = "M";
  686.     ShellOptions->max += maintab->m_option5.m_sizemax;
  687.   } else ShellOptions->max = "";
  688.   
  689.   if(maintab->m_option5.m_pausebytes!=""){
  690.     ShellOptions->frag = "G";
  691.     ShellOptions->frag += maintab->m_option5.m_pausebytes;
  692.   } else ShellOptions->frag = "";
  693.   
  694.   
  695.   if(maintab->m_option5.m_maxhtml!="" || maintab->m_option5.m_othermax!="" ){
  696.     ShellOptions->maxfile = "m";
  697.     if(maintab->m_option5.m_othermax!="") ShellOptions->maxfile += maintab->m_option5.m_othermax;
  698.     else ShellOptions->maxfile += "0";
  699.     if(maintab->m_option5.m_maxhtml!="") {ShellOptions->maxfile += ",";ShellOptions->maxfile += maintab->m_option5.m_maxhtml;}
  700.     else {ShellOptions->maxfile += ",";ShellOptions->maxfile += "0";}
  701.   } else ShellOptions->maxfile = "";
  702.   
  703.   if(strcmp(maintab->m_option4.m_connexion,"")!=0){
  704.     ShellOptions->conn = "c";
  705.     ShellOptions->conn += maintab->m_option4.m_connexion;
  706.   } else ShellOptions->conn = "";
  707.   
  708.   if(strcmp(maintab->m_option4.m_timeout,"")!=0){
  709.     ShellOptions->time = "T";
  710.     ShellOptions->time += maintab->m_option4.m_timeout;
  711.   } else ShellOptions->time = "";
  712.   
  713.   // quitter host si timeout ou rate out
  714.   ShellOptions->hostquit = "";
  715.   {
  716.     int a=0;
  717.     if (maintab->m_option4.m_remt)
  718.       a+=1;
  719.     if (maintab->m_option4.m_rems)
  720.       a+=2;
  721.     ShellOptions->hostquit.Format("H%d",a);
  722.   }
  723.  
  724.   // Keep-Alive
  725.   if (maintab->m_option4.m_ka) {
  726.     ShellOptions->ka = "%k";
  727.   } else {
  728.     ShellOptions->ka = "%k0";
  729.   }
  730.  
  731.   
  732.   //--> max time
  733.   if(strcmp(maintab->m_option5.m_maxtime,"")!=0){
  734.     ShellOptions->maxtime = "E";
  735.     ShellOptions->maxtime += maintab->m_option5.m_maxtime;
  736.   } else ShellOptions->maxtime = "";
  737.   
  738.   //--> max rate
  739.   if(strcmp(maintab->m_option5.m_maxrate,"")!=0){
  740.     ShellOptions->maxrate = "A";
  741.     ShellOptions->maxrate += maintab->m_option5.m_maxrate;
  742.   } else ShellOptions->maxrate = "";
  743.   
  744.   if(strcmp(maintab->m_option5.m_maxconn,"")!=0){
  745.     ShellOptions->maxconn = "%c";
  746.     ShellOptions->maxconn += maintab->m_option5.m_maxconn;
  747.   } else ShellOptions->maxconn = "";
  748.   
  749.   if(strcmp(maintab->m_option5.m_maxlinks,"")!=0){
  750.     ShellOptions->maxlinks = "#L";
  751.     ShellOptions->maxlinks += maintab->m_option5.m_maxlinks;
  752.   } else ShellOptions->maxlinks = "";
  753.   
  754.   if(strcmp(maintab->m_option4.m_rate,"")!=0){
  755.     ShellOptions->rate = "J";
  756.     ShellOptions->rate += maintab->m_option4.m_rate;
  757.   } else ShellOptions->rate = "";
  758.   
  759.   if(strcmp(maintab->m_option6.m_user,"")!=0){
  760.     ShellOptions->user = "\"";
  761.     ShellOptions->user += maintab->m_option6.m_user;
  762.     ShellOptions->user += "\"";
  763.   } else ShellOptions->user = "";
  764.   
  765.   if(strcmp(maintab->m_option6.m_footer,"")!=0){
  766.     ShellOptions->footer = "\"";
  767.     ShellOptions->footer += maintab->m_option6.m_footer;
  768.     ShellOptions->footer += "\"";
  769.   } else ShellOptions->footer = "";
  770.   
  771.   if(strcmp(maintab->m_option4.m_retry,"")!=0){
  772.     ShellOptions->retry = "R";
  773.     ShellOptions->retry += maintab->m_option4.m_retry;
  774.   } else ShellOptions->retry = "";
  775.   
  776.   if(strcmp(maintab->m_option7.m_url2,"")!=0){
  777.     ShellOptions->buff_filtres = maintab->m_option7.m_url2;
  778.   } else ShellOptions->buff_filtres = "";
  779.   
  780.   
  781.   // MIME
  782.   ShellOptions->buff_MIME = "";
  783.   ADD_MIME_IN_COPT(1)
  784.     ADD_MIME_IN_COPT(2)
  785.     ADD_MIME_IN_COPT(3)
  786.     ADD_MIME_IN_COPT(4)
  787.     ADD_MIME_IN_COPT(5)
  788.     ADD_MIME_IN_COPT(6)
  789.     ADD_MIME_IN_COPT(7)
  790.     ADD_MIME_IN_COPT(8)
  791.     
  792.     /* autres options: RAS */
  793.     if (dialog2->m_rasdisc)
  794.       disconnect=1;     /* dΘconnexion α la fin */
  795.     else
  796.       disconnect=0;
  797.  
  798.     /* autres options: Shutdown */
  799.     if (dialog2->m_rasshut)
  800.       shutdown_pc=1;     /* Θtendre α la fin */
  801.     else
  802.       shutdown_pc=0;
  803. }
  804.  
  805. /* From MSDN: */
  806. void CALLBACK
  807. MessageBoxTimer(HWND hwnd, UINT uiMsg, UINT idEvent, DWORD dwTime)
  808. {
  809.   PostQuitMessage(0);
  810. }
  811. UINT
  812. TimedMessageBox(
  813.                 HWND hwndParent,
  814.                 LPCTSTR ptszMessage,
  815.                 LPCTSTR ptszTitle,
  816.                 UINT flags,
  817.                 DWORD dwTimeout)
  818. {
  819.   UINT_PTR idTimer;
  820.   UINT uiResult;
  821.   MSG msg;
  822.  
  823.   /*
  824.   *  Set a timer to dismiss the message box.
  825.   */ 
  826.   idTimer = SetTimer(NULL, 0, dwTimeout, (TIMERPROC)MessageBoxTimer);
  827.  
  828.   uiResult = MessageBox(hwndParent, ptszMessage, ptszTitle, flags);
  829.  
  830.   /*
  831.   *  Finished with the timer.
  832.   */ 
  833.   KillTimer(NULL, idTimer);
  834.  
  835.   /*
  836.   *  See if there is a WM_QUIT message in the queue. If so,
  837.   *  then you timed out. Eat the message so you don't quit the
  838.   *  entire application.
  839.   */ 
  840.   if (PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE)) {
  841.  
  842.     /*
  843.     *  If you timed out, then return zero.
  844.     */ 
  845.     uiResult = 0;
  846.   }
  847.  
  848.   return uiResult;
  849. }
  850.  
  851. /* From MSDN */
  852. BOOL InitiateSystemShutdownExWithPriv(
  853.   LPTSTR lpMessage,
  854.   DWORD dwTimeout,
  855.   BOOL bForceAppsClosed,
  856.   BOOL bRebootAfterShutdown,
  857.   DWORD dwReason)
  858. {
  859.    HANDLE hToken;              // handle to process token 
  860.    TOKEN_PRIVILEGES tkp;       // pointer to token structure 
  861.  
  862.    BOOL fResult;               // system shutdown flag 
  863.  
  864.    // Get the current process token handle so we can get shutdown 
  865.    // privilege. 
  866.  
  867.    if (!OpenProcessToken(GetCurrentProcess(), 
  868.         TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) 
  869.       return FALSE; 
  870.  
  871.    // Get the LUID for shutdown privilege. 
  872.  
  873.    LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, 
  874.         &tkp.Privileges[0].Luid); 
  875.  
  876.    tkp.PrivilegeCount = 1;  // one privilege to set    
  877.    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 
  878.  
  879.    // Get shutdown privilege for this process. 
  880.  
  881.    AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, 
  882.       (PTOKEN_PRIVILEGES) NULL, 0); 
  883.  
  884.    // Cannot test the return value of AdjustTokenPrivileges. 
  885.  
  886.    if (GetLastError() != ERROR_SUCCESS) 
  887.       return FALSE; 
  888.  
  889.    // Display the shutdown dialog box and start the countdown. 
  890.  
  891. #if 0
  892.   fResult = InitiateSystemShutdownEx(
  893.     NULL,
  894.     lpMessage,
  895.     dwTimeout,
  896.     bForceAppsClosed,
  897.     bRebootAfterShutdown,
  898.     dwReason
  899.     );
  900. #else
  901. #ifndef EWX_FORCEIFHUNG
  902. #define EWX_FORCEIFHUNG     0x00000010
  903. #endif
  904.    UINT msgRes = TimedMessageBox(NULL, lpMessage, _T("Shutdown"), 
  905.      MB_OKCANCEL  | MB_SYSTEMMODAL | MB_ICONEXCLAMATION, 
  906.      dwTimeout*1000);
  907.      if (msgRes == 0 || msgRes == IDOK) {
  908.        fResult = ExitWindowsEx(EWX_LOGOFF | EWX_POWEROFF | EWX_FORCEIFHUNG, dwReason);
  909.      } else {
  910.        fResult = 0;
  911.      }
  912. #endif
  913.  
  914.    // Disable shutdown privilege.
  915.    tkp.Privileges[0].Attributes = 0; 
  916.    AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, 
  917.         (PTOKEN_PRIVILEGES) NULL, 0); 
  918.  
  919.    if (!fResult) 
  920.       return FALSE; 
  921.    return TRUE; 
  922. }
  923.  
  924.  
  925. // Les routines α dΘfinir:
  926. int __cdecl httrackengine_check(t_hts_callbackarg *carg, httrackp *opt, const char* adr,const char* fil,int status) {  // appelΘ par le wizard
  927.   return -1;
  928. }
  929. int __cdecl httrackengine_check_mime(t_hts_callbackarg *carg, httrackp *opt, const char* adr,const char* fil,const char* mime,int status) {  // appelΘ par le wizard
  930.   ATLTRACE(__FUNCTION__ " : check %s%s : <%s>\r\n", adr, fil, mime);
  931.   return -1;
  932. }
  933. EXECUTION_STATE (WINAPI * SetThreadExecutionState_)(IN EXECUTION_STATE) = NULL;
  934. void __cdecl httrackengine_init(t_hts_callbackarg *carg) {    // appelΘ lors de l'init de HTTRACK, avant le dΘbut d'un miroir
  935.   ATLTRACE(__FUNCTION__ " : init\r\n");
  936.   // Finished
  937.   PlaySound("MirrorStarted", NULL, SND_ASYNC | SND_NOWAIT | SND_APPLICATION);
  938.  
  939. #if USE_RAS
  940.   has_started=0;
  941. #endif
  942.  
  943.   /* Dynamic SetThreadExecutionState_ */
  944.   if (SetThreadExecutionState_ == NULL) {
  945.     HANDLE handle = LoadLibraryA("Kernel32.dll");
  946.     if (handle != INVALID_HANDLE_VALUE) {
  947.       SetThreadExecutionState_ = (EXECUTION_STATE (__stdcall *)(EXECUTION_STATE)) GetProcAddress((HMODULE)handle, "SetThreadExecutionState");
  948.     }
  949.   }
  950.  
  951.   httrackengine_loop(NULL, NULL, NULL, 0,0,0,0,NULL,0);  // init
  952.   //printf("DEMARRAGE DU MIROIR DETECTE\n");  
  953. }
  954. void __cdecl httrackengine_uninit(t_hts_callbackarg *carg) {  // appelΘ en fin de miroir (peut Ωtre utile!!!)
  955.   ATLTRACE(__FUNCTION__ " : uninit\r\n");
  956.   // Finished
  957.   PlaySound("MirrorFinished", NULL, SND_ASYNC | SND_NOWAIT | SND_APPLICATION);
  958.  
  959.  // Disconnect RAS
  960. #if USE_RAS
  961.   if (LibRasUse) {        /* librairie RAS chargΘe */
  962.     if (disconnect) {     /* on doit dΘconnecter */
  963.       if (connected) {    /* on a initiΘ une connexion */
  964.         if (conn)
  965.           LibRas->RasHangUp(conn);
  966.       } else {            /* tout dΘconnecter */
  967.         // On coupe tout (non, pas bourrin)
  968.         DWORD size;
  969.         RASCONN* adr;
  970.         int count=256;
  971.         size = sizeof(RASCONN)*(count+2);
  972.         adr = (RASCONN*) (char*) calloc(size,1);
  973.         if (adr) {
  974.           DWORD ent;
  975.           int i;
  976.           for(i=0;i<count;i++) {
  977.             adr[i].dwSize=sizeof(RASCONN);
  978.             strcpybuff(adr[i].szEntryName,"");
  979.           }
  980.           if (LibRas->RasEnumConnections((RASCONN*) adr,&size,&ent) == 0) {
  981.             for(i=0;i<(int)ent;i++) {
  982.               LibRas->RasHangUp(adr[i].hrasconn);
  983.             }
  984.           }
  985.           free(adr);
  986.         }
  987.         
  988.       }
  989.     }
  990.   }
  991. #endif
  992.  
  993.   // Shutdown PC
  994.   if (shutdown_pc) {
  995.     //ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, 
  996.     //  SHTDN_REASON_MAJOR_APPLICATION | SHTDN_REASON_MINOR_OTHER);
  997.     InitiateSystemShutdownExWithPriv( 
  998.       _T(
  999.         "WinHTTrack has finished the mirror, the system will soon reboot.\r\n"
  1000.         "Click 'OK' to reboot.\r\n"
  1001.         "** CLICK NOW 'CANCEL' TO CANCEL THE REBOOT! **\r\n"
  1002.       ),
  1003.       6,
  1004.       TRUE /* bForceAppsClosed */,
  1005.       FALSE /* bRebootAfterShutdown */,
  1006.       SHTDN_REASON_MAJOR_APPLICATION | SHTDN_REASON_MINOR_OTHER
  1007.       );
  1008.   }
  1009. }
  1010. int __cdecl httrackengine_start(t_hts_callbackarg *carg, httrackp *opt) {   // appelΘ lors du dΘmarrage du miroir (premiΦres requΦtes)
  1011.   ATLTRACE(__FUNCTION__ " : starting\r\n");
  1012. #if USE_RAS
  1013.   // connexion RAS
  1014.   has_started=1;    // dΘmarrage
  1015.   connected=0;
  1016.   conn = NULL;
  1017.   memset(&SInfo, 0, sizeof(SInfo));
  1018.   if (LibRasUse) {
  1019.     if (ShellOptions->_RasString.GetLength()>0) {    // sΘlection provider
  1020.       if (!LibRas->RasDial(NULL,NULL,&ShellOptions->_dial,NULL,NULL,&conn)) {
  1021.         RASCONNSTATUS status;
  1022.         do {
  1023.           status.dwSize = sizeof(status);
  1024.           LibRas->RasGetConnectStatus(conn,&status);
  1025.           switch(status.rasconnstate) {
  1026.           case RASCS_Connected : 
  1027.             connected=1;
  1028.             break;
  1029.           case RASCS_Disconnected :
  1030.             strcpybuff(connected_err,LANG(LANG_F3 /*"Could not connect to provider"*/));
  1031.             connected=-1;
  1032.             break;
  1033.           }
  1034.         } while(connected==0);
  1035.       } else {
  1036.         strcpybuff(connected_err,LANG(LANG_F3 /*"Could not connect to provider","Impossible d'Θtablir la connexion"*/));
  1037.         connected=-1;
  1038.         //termine=1;
  1039.       }
  1040.     }
  1041.     //
  1042.     if (connected != -1)  // si pas d'erreur RAS
  1043.       return 1;
  1044.     else
  1045.       return 0;
  1046.   } else
  1047.     return 1;
  1048. #else
  1049.   return 1;
  1050. #endif
  1051. }
  1052. int  httrackengine_end(t_hts_callbackarg *carg, httrackp *opt) {     // appelΘ lors de la fin du miroir (plus de liens α charger)
  1053.   ATLTRACE(__FUNCTION__ " : end\r\n");
  1054.   WHTT_LOCK();
  1055.   termine=1;
  1056.   if (_Cinprogress_inst) {
  1057.     _Cinprogress_inst->EndDialog(IDOK);
  1058.     _Cinprogress_inst=NULL;
  1059.   }
  1060.   WHTT_UNLOCK();
  1061.   return 1;
  1062. }
  1063. int __cdecl httrackengine_htmlpreprocess(t_hts_callbackarg *carg, httrackp *opt, char** html,int* len,const char* url_address,const char* url_file) {
  1064.   ATLTRACE(__FUNCTION__ " : preprocessing %s%s (%d bytes)\r\n", url_address, url_file, *len);
  1065.   return 1;
  1066. }
  1067. int __cdecl httrackengine_htmlpostprocess(t_hts_callbackarg *carg, httrackp *opt, char** html,int* len,const char* url_address,const char* url_file) {
  1068.   ATLTRACE(__FUNCTION__ " : postprocessing %s%s (%d bytes)\r\n", url_address, url_file, *len);
  1069.   //char *old = *html;
  1070.   //*html = hts_strdup(*html);
  1071.   //hts_free(old);
  1072.   return 1;
  1073. }
  1074. int __cdecl httrackengine_htmlcheck(t_hts_callbackarg *carg, httrackp *opt, char* html,int len,const char* url_address,const char* url_file) {    // appelΘ α chaque fois qu'un html doit Ωtre scannΘ (utile pour la prospection mais inutile ici)
  1075.   return 1;
  1076. }
  1077. int __cdecl httrackengine_chopt(t_hts_callbackarg *carg, httrackp *opt) {
  1078.   ATLTRACE(__FUNCTION__ " : changing options\r\n");
  1079.   return 1;
  1080. }
  1081. void __cdecl httrackengine_filesave(t_hts_callbackarg *carg, httrackp *opt, const char* file) {
  1082. }
  1083. void __cdecl httrackengine_filesave2(t_hts_callbackarg *carg, httrackp *opt, const char* adr, const char* fil, const char* save, int is_new, int is_modified, int not_updated) {
  1084.   ATLTRACE(__FUNCTION__ " : saving %s%s as %s (new=%d, modified=%d, notupdated=%d)\r\n", adr, fil, save, is_new, is_modified, not_updated);
  1085. }
  1086.  
  1087. // Le routine la plus utile sans doute: elle refresh les tableaux
  1088. // C'est la 2e routine en thread qui assure le refresh graphique
  1089. // (plus efficace)
  1090. // -->C'est elle qui dΘcide de tout arrΩter si elle dΘtecte in termine_request<--
  1091. int __cdecl httrackengine_loop(t_hts_callbackarg *carg, httrackp *opt,
  1092.                                lien_back* back,int back_max,int back_index,
  1093.                                int lien_n,int lien_tot,
  1094.                                int stat_time,
  1095.                                hts_stat_struct* stats) {    // appelΘ α chaque boucle de HTTrack
  1096.   static char s[HTS_URLMAXSIZE*2]="";  // utilisΘ plus loin
  1097.   int stat_written=-1;
  1098.   int stat_updated=-1;
  1099.   int stat_errors=-1;
  1100.   int stat_warnings=-1;
  1101.   int stat_infos=-1;
  1102.   int nbk=-1;
  1103.   LLint nb=-1;
  1104.   int stat_nsocket=-1;
  1105.   LLint stat_bytes=-1;
  1106.   LLint stat_bytes_recv=-1;
  1107.   int irate=-1;
  1108.  
  1109.   /* Mutex */
  1110.   WHTT_LOCK();
  1111.  
  1112.   /* Forces the system to be in the working state by resetting the system idle timer. */
  1113.   if (SetThreadExecutionState_ != NULL)
  1114.     SetThreadExecutionState_(ES_SYSTEM_REQUIRED);
  1115.  
  1116.   if (stats) {
  1117.     stat_written=stats->stat_files;
  1118.     stat_updated=stats->stat_updated_files;
  1119.     stat_errors=stats->stat_errors;
  1120.     stat_warnings=stats->stat_warnings;
  1121.     stat_infos=stats->stat_infos;
  1122.     nbk=stats->nbk;
  1123.     stat_nsocket=stats->stat_nsocket;
  1124.     irate=(int)stats->rate;
  1125.     nb=stats->nb;
  1126.     stat_bytes=stats->nb;
  1127.     stat_bytes_recv=stats->HTS_TOTAL_RECV;
  1128.   }
  1129.   
  1130. #if !SHELL_MULTITHREAD
  1131.   static TStamp last_time;
  1132. #endif
  1133.   int rate;
  1134.   
  1135.   if (back_max == 0) {
  1136. #if !SHELL_MULTITHREAD
  1137.     last_time=0;
  1138. #endif
  1139.     // en cas de manque de time
  1140.     SInfo.refresh=1;
  1141.     SInfo.stat_timestart=time_local();
  1142.     WHTT_UNLOCK();
  1143.     return 1;
  1144.   }
  1145.   
  1146.   if ((termine) || (termine_requested)) {
  1147.     SInfo.refresh=0;      // pas de refresh
  1148.     SInfo.refresh=0;      // pas de refresh
  1149.     termine_requested=1;
  1150.     WHTT_UNLOCK();
  1151.     return 0;
  1152.   }
  1153.   
  1154.   if (stat_written>=0) SInfo.stat_written=stat_written;
  1155.   if (stat_updated>=0) SInfo.stat_updated=stat_updated;
  1156.   if (stat_errors>=0)  SInfo.stat_errors=stat_errors;
  1157.   if (stat_warnings>=0)  SInfo.stat_warnings=stat_warnings;
  1158.   if (stat_infos>=0)  SInfo.stat_infos=stat_infos;
  1159.   
  1160. #if SHELL_MULTITHREAD 
  1161.   //if (((tl-last_time)>=100) || ((tl-last_time)<0)) {   // chaque 100 ms
  1162.   if (SInfo.ask_refresh) {
  1163. #else
  1164.     TStamp tl=0;
  1165.     {
  1166.       time_t tt;
  1167.       struct tm* A;
  1168.       tt=time(NULL);
  1169.       A=localtime(&tt);
  1170.       tl+=A->tm_sec;
  1171.       tl+=A->tm_min*60;
  1172.       tl+=A->tm_hour*60*60;
  1173.       //tl+=A->tm_yday*60*60*24;
  1174.       //tl+=A->tm_year*60*60*24*365;
  1175.       
  1176.       tl*=1000;  // en ms
  1177.       
  1178.       struct _timeb timebuffer;
  1179.       char *timeline;
  1180.       _ftime( &timebuffer );
  1181.       timeline = ctime( & ( timebuffer.time ) );
  1182.       
  1183.       tl+=timebuffer.millitm;    // + ms
  1184.     }
  1185.     if (((tl-last_time)>=HTS_SLEEP_WIN) || ((tl-last_time)<0)) {   // chaque 250 ms
  1186.       last_time=tl;
  1187. #endif
  1188.       //INFILLMEM_LOCKED=1;    // locker interface
  1189.       // OPTI int rate;
  1190.       SInfo.ask_refresh=0;
  1191.       
  1192.       // pour Θviter temps cpu consommΘ trop grand
  1193.       // Sleep(10);
  1194.       
  1195.       // initialiser ft
  1196.       if ((stat_nsocket==-1)) {
  1197.         if (SInfo.ft==-1) {
  1198.           SInfo.ft=stat_time;
  1199.         }
  1200.       }
  1201.       
  1202. #if !SHELL_MULTITHREAD
  1203.       //
  1204.       MSG msg;  
  1205.       if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE )) {     
  1206.         switch (msg.message) {
  1207.         case WM_COMMAND:        
  1208.           switch(msg.wParam) { 
  1209.           case ID_APP_ABOUT: {
  1210.             Cabout about;
  1211.             about.DoModal();                                    }
  1212.             break;
  1213.           case ID_APP_EXIT: case WM_CLOSE :
  1214.             termine_requested=1;
  1215.             break;
  1216.           case  WM_DESTROY: case WM_NCDESTROY: 
  1217.             termine_requested=1;
  1218.             break;
  1219.           }
  1220.           break;        
  1221.           default:
  1222.             DefWindowProc(msg.hwnd,msg.message,msg.wParam,msg.lParam);
  1223.             break;
  1224.         }
  1225.       }
  1226.       //
  1227. #endif
  1228.       
  1229.       // calculer heure si ce n'est dΘja fait
  1230.       if (stat_time<0)
  1231.         SInfo.stat_time=(int) (time_local()-SInfo.stat_timestart);
  1232.       
  1233.       // calculer transfer rate
  1234.       if ((stat_time>0) && (stat_bytes_recv>0))
  1235.         rate=(int)(stat_bytes_recv/stat_time);
  1236.       else
  1237.         rate=0;    // pas d'infos
  1238.       
  1239.       // stocker infos: octets transfΘrΘs, temps, etc.
  1240.       if (stat_bytes>=0) SInfo.stat_bytes=stat_bytes;      // bytes
  1241.       if (stat_time>=0) SInfo.stat_time=stat_time;         // time
  1242.       if (lien_tot>=0) SInfo.lien_tot=lien_tot; // nb liens
  1243.       if (lien_n>=0) SInfo.lien_n=lien_n;       // scanned
  1244.       SInfo.stat_nsocket=stat_nsocket;          // socks
  1245.       if (rate>0)  SInfo.rate=rate;                // rate
  1246.       if (irate>=0) SInfo.irate=irate;             // irate
  1247.       if (SInfo.irate<0) SInfo.irate=SInfo.rate;
  1248.       if (nbk>=0) SInfo.stat_back=nbk;
  1249.       
  1250.       // back: tableau de back_max ΘlΘments de cache
  1251.       // back_max: nombre d'ΘlΘments ^^^^
  1252.       // lien_tot: nombre total de liens traitΘs pour le moment
  1253.       // stat_bytes: octets sauvegardΘs
  1254.       // stat_bytes_recv: octets tΘlΘchargΘs
  1255.       // stat_time: temps en seconde depuis le dΘbut du miroir
  1256.       // stat_nsocket: nombre de sockets connectΘes actuellement
  1257.       // on peut en dΘduire rate=stat_bytes_recv/stat_time
  1258.       
  1259.       // printf("loop.. %d liens, %d octets, %d secondes, %d sockets, TAUX=%d\n",lien_tot,stat_bytes,stat_time,stat_nsocket,rate);
  1260.       
  1261.       // parcourir registre des liens
  1262.       if (back_index>=0) {  // seulement si index passΘ
  1263.         int j,k;
  1264.         int index=0;
  1265.         int ok=0;         // idem
  1266.         int l;            // idem
  1267.         int M=32;         // idem
  1268.         
  1269.         StatsBufferback=(void*) back;
  1270.         StatsBufferback_max=back_max;
  1271.         {
  1272.           int i;
  1273.           for(i=0;i<NStatsBuffer;i++) {
  1274.             strcpybuff(StatsBuffer[i].etat,"");
  1275.             strcpybuff(StatsBuffer[i].nom,"");
  1276.             strcpybuff(StatsBuffer[i].fichier,"");
  1277.             strcpybuff(StatsBuffer[i].url_sav,"");
  1278.             StatsBuffer[i].back=NULL;
  1279.             StatsBuffer[i].size=0;
  1280.             StatsBuffer[i].sizetot=0;
  1281.           }
  1282.         }
  1283.         for(k=0;k<2;k++) {    // 0: lien en cours 1: autres liens
  1284.           for(j=0;(j<3) && (index<NStatsBuffer);j++) {  // passe de prioritΘ
  1285.             int _i;
  1286.             for(_i=0+k;(_i< max(back_max*k,1) ) && (index<NStatsBuffer);_i++) {  // no lien
  1287.               int i=(back_index+_i)%back_max;    // commencer par le "premier" (l'actuel)
  1288.               if (back[i].status>=0) {     // signifie "lien actif"
  1289.                 // int ok=0;  // OPTI
  1290.                 ok=0;
  1291.                 switch(j) {
  1292.                 case 0:     // prioritaire
  1293.                   if ((back[i].status>0) && (back[i].status<99)) {
  1294.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F4 /*"receive","rΘception"*/)); ok=1;
  1295.                   }
  1296.                   break;
  1297.                 case 1:
  1298.                   if (back[i].status==99) {
  1299.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F5 /*"request","requΦte"*/)); ok=1;
  1300.                   }
  1301.                   else if (back[i].status==STATUS_CONNECTING) {
  1302.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F6 /*"connect","connexion"*/)); ok=1;
  1303.                   }
  1304.                   else if (back[i].status==101) {
  1305.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F7 /*"search","recherche"*/)); ok=1;
  1306.                   }
  1307.                   else if (back[i].status==1000) {    // ohh le beau ftp
  1308.                                         char proto[] = "ftp";
  1309.                                         if (back[i].url_adr[0]) {
  1310.                                             char* ep = strchr(back[i].url_adr, ':');
  1311.                                             char* eps = strchr(back[i].url_adr, '/');
  1312.                                             int count;
  1313.                                             if (ep != NULL && ep < eps && (count = (int) (ep - back[i].url_adr) ) < 4) {
  1314.                                                 proto[0] = '\0';
  1315.                                                 strncat(proto, back[i].url_adr, count);
  1316.                                             }
  1317.                                         }
  1318.                     sprintf(StatsBuffer[index].etat,"%s: %s",proto,back[i].info); ok=1;
  1319.                   }
  1320.                   else if (back[i].status==102) {         // SSL handshake
  1321.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F6 /*"connect","connexion"*/)); ok=1;
  1322.                   }
  1323.                   else if (back[i].status==STATUS_ALIVE) {         // waiting (keep-alive)
  1324.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F8)); ok=1;
  1325.                   }
  1326.                   break;
  1327.                 default:
  1328.                   if (back[i].status==0) {  // prΩt
  1329.                     if ((back[i].r.statuscode==200)) {
  1330.                       strcpybuff(StatsBuffer[index].etat,LANG(LANG_F8 /*"ready","prΩt"*/)); ok=1;
  1331.                     }
  1332.                     else if ((back[i].r.statuscode>=100) && (back[i].r.statuscode<=599)) {
  1333.                       char tempo[256]; tempo[0]='\0';
  1334.                       infostatuscode(tempo,back[i].r.statuscode);
  1335.                       strcpybuff(StatsBuffer[index].etat,tempo); ok=1;
  1336.                     }
  1337.                     else {
  1338.                       strcpybuff(StatsBuffer[index].etat,LANG(LANG_F9 /*"error","erreur"*/)); ok=1;
  1339.                     }
  1340.                   }
  1341.                   break;
  1342.                 }
  1343.                 
  1344.                 if (ok) {
  1345.                   // OPTI int l;
  1346.                   // OPTI int M=32;     // longueur
  1347.                   // OPTI char s[HTS_URLMAXSIZE*2]="";
  1348.                   //
  1349.                   StatsBuffer[index].back=i;        // index pour + d'infos
  1350.                   //
  1351.                   s[0]='\0';
  1352.                   strcpybuff(StatsBuffer[index].url_sav,back[i].url_sav);   // pour cancel
  1353.                   if (strcmp(back[i].url_adr,"file://"))
  1354.                     strcatbuff(s,back[i].url_adr);
  1355.                   else
  1356.                     strcatbuff(s,"localhost");
  1357.                   if (back[i].url_fil[0]!='/')
  1358.                     strcatbuff(s,"/");
  1359.                   strcatbuff(s,back[i].url_fil);
  1360.                   
  1361.                   StatsBuffer[index].fichier[0]='\0';
  1362.                   {
  1363.                     char* a=strrchr(s,'/');
  1364.                     if (a) {
  1365.                       strncatbuff(StatsBuffer[index].fichier,a,200);
  1366.                       *a='\0';
  1367.                     }
  1368.                   }
  1369.                   
  1370.                   if ((l = (int) strlen(s))<MAX_LEN_INPROGRESS)
  1371.                     strcpybuff(StatsBuffer[index].nom,s);
  1372.                   else {
  1373.                     // couper
  1374.                     StatsBuffer[index].nom[0]='\0';
  1375.                     strncatbuff(StatsBuffer[index].nom,s,MAX_LEN_INPROGRESS/2-2);
  1376.                     strcatbuff(StatsBuffer[index].nom,"...");
  1377.                     strcatbuff(StatsBuffer[index].nom,s+l-MAX_LEN_INPROGRESS/2+2);
  1378.                   }
  1379.                   
  1380.                   //if (back[i].url_fil[0]!='/') printf("/");
  1381.                   
  1382.                   if (back[i].r.totalsize>0) {  // taille prΘdΘfinie
  1383.                     StatsBuffer[index].sizetot=back[i].r.totalsize;
  1384.                     StatsBuffer[index].size=back[i].r.size;
  1385.                   } else {  // pas de taille prΘdΘfinie
  1386.                     if (back[i].status==0) {  // prΩt
  1387.                       StatsBuffer[index].sizetot=back[i].r.size;
  1388.                       StatsBuffer[index].size=back[i].r.size;
  1389.                     } else {
  1390.                       StatsBuffer[index].sizetot=8192;
  1391.                       StatsBuffer[index].size=(back[i].r.size % 8192);
  1392.                     }
  1393.                   }
  1394.                   index++;
  1395.                 }
  1396.               }
  1397.             }
  1398.           }
  1399.         }
  1400.     }
  1401.     
  1402. #if SHELL_MULTITHREAD
  1403.     SInfo.refresh=1;     // on signale qu'il faut faire un refresh!
  1404. #else
  1405.     inprogress_refresh();  // tout de suite (non multithread)
  1406. #endif
  1407.     // INFILLMEM_LOCKED=0;    // dΘlocker interface
  1408.   }
  1409.   WHTT_UNLOCK();
  1410.   return (termine==0);
  1411. }
  1412.  
  1413. int inprogress_refresh() {
  1414.     strc_int2bytes2 strc, strc2;
  1415.   static int toggle=0;
  1416.   // WHTT_LOCK(); // deja fait
  1417.   if ((!termine) && (!termine_requested) && (inprogress->m_hWnd)) {
  1418.     if (SInfo.refresh) {
  1419.       // INREDRAW_LOCKED=1;
  1420.       // REFRESH (si nb de socket==-1 on manage les fenetres)
  1421.       int icn;
  1422.       icn=inprogress->IsIconic();
  1423.       CString lnk;
  1424.       if (SInfo.stat_back)
  1425.         lnk.Format("%d/%d (+%d)",SInfo.lien_n,SInfo.lien_tot-1,SInfo.stat_back);
  1426.       else
  1427.         lnk.Format("%d/%d",SInfo.lien_n,SInfo.lien_tot-1);
  1428.       if (!icn) {
  1429.         int parsing=0;
  1430.         if (!soft_term_requested) {
  1431.           if (!hts_setpause(global_opt, -1)) {
  1432.             if (!(parsing=hts_is_parsing(global_opt, -1)))
  1433.               SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F10 /*"Receiving files.","RΘception des fichiers"*/)); 
  1434.             else {
  1435.               switch(hts_is_testing(global_opt)) {
  1436.               case 0:
  1437.                 SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F11 /*"Parsing HTML file..","Parcours du fichier HTML"*/)); 
  1438.                 break;
  1439.               case 1:
  1440.                 SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F12 /*"Parsing HTML file (testing links)..","Parcours du fichier HTML (test des liens)"*/)); 
  1441.                 break;
  1442.               case 2:
  1443.                 SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F11b)); 
  1444.                 break;
  1445.               case 3:
  1446.                 SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F11c)); 
  1447.                 break;
  1448.               case 4:
  1449.                 SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F15)); 
  1450.                 break;
  1451.               case 5:
  1452.                 SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F15b)); 
  1453.                 break;
  1454.               }
  1455.             }
  1456.           } else {
  1457.             if (((toggle++)/5)%2)
  1458.               SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F13 /*"Paused (select [File]/[Pause transfer] to continue)","Interrompu (choisir [Fichier]/[Interrompre transferts] pour continuer)"*/));
  1459.             else
  1460.               SetDlgItemTextCP(inprogress, IDC_inforun,"");
  1461.           }
  1462.         } else {
  1463.           if (((toggle++)/5)%2)
  1464.             SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F13b));
  1465.           else
  1466.             SetDlgItemTextCP(inprogress, IDC_inforun,"");
  1467.         }
  1468.         
  1469.         if (SInfo.stat_time>0) {
  1470.           char s[256];
  1471.           qsec2str(s,(TStamp) SInfo.stat_time);
  1472.           SetDlgItemTextCP(inprogress, IDC_i1 ,s);  // time
  1473.         } else
  1474.           SetDlgItemTextCP(inprogress, IDC_i1 , _SN(SInfo.stat_time) );  // time
  1475.         SetDlgItemTextCP(inprogress, IDC_i0 , int2bytes(&strc, SInfo.stat_bytes) );  // bytes
  1476.         SetDlgItemTextCP(inprogress, IDC_i2 , lnk);  // scanned
  1477.         if (SInfo.stat_nsocket>0)
  1478.           SetDlgItemTextCP(inprogress, IDC_i3 , _SN(SInfo.stat_nsocket) );  // socks
  1479.         else
  1480.           SetDlgItemTextCP(inprogress, IDC_i3 , "none" );  // wait
  1481.         
  1482.         CString st;
  1483.         st.Format("%s (%s)", int2bytessec(&strc, SInfo.irate), int2bytessec(&strc2, SInfo.rate));
  1484.         SetDlgItemTextCP(inprogress, IDC_i4 , st );  // rate
  1485.         
  1486.         SetDlgItemTextCP(inprogress, IDC_i5 , _SN(SInfo.stat_errors) );
  1487.         SetDlgItemTextCP(inprogress, IDC_i6 , _SN(SInfo.stat_written) );
  1488.         {
  1489.           char tempo[256];
  1490.           int pc=0;
  1491.           if (SInfo.stat_written)
  1492.             pc=(int)((SInfo.stat_updated*100)/(SInfo.stat_written));
  1493.           if (pc)
  1494.             sprintf(tempo,"%d (%d%%)",SInfo.stat_updated,pc);
  1495.           else
  1496.             sprintf(tempo,"%d",SInfo.stat_updated);
  1497.           SetDlgItemTextCP(inprogress, IDC_i7 , tempo );
  1498.         }
  1499.         
  1500.         /*if (!parsing)*/
  1501.         {
  1502.           {
  1503.             int i;
  1504.             for(i=0;i<NStatsBuffer;i++) {
  1505.               if (StatsBuffer[i].sizetot>0) {
  1506.                 TStamp d = ((TStamp) StatsBuffer[i].size * 1000);
  1507.                 d = d / ((TStamp) StatsBuffer[i].sizetot);
  1508.                 StatsBuffer[i].offset = (int) d;
  1509.               } else
  1510.                 StatsBuffer[i].offset = 0;
  1511.             }
  1512.           }
  1513.           
  1514.           if (!parsing)
  1515.             inprogress->m_sl0.SetRange(0,1000);
  1516.           inprogress->m_sl1.SetRange(0,1000);
  1517.           inprogress->m_sl2.SetRange(0,1000);
  1518.           inprogress->m_sl3.SetRange(0,1000);
  1519.           inprogress->m_sl4.SetRange(0,1000);
  1520.           inprogress->m_sl5.SetRange(0,1000);
  1521.           inprogress->m_sl6.SetRange(0,1000);
  1522.           inprogress->m_sl7.SetRange(0,1000);
  1523.           inprogress->m_sl8.SetRange(0,1000);
  1524.           inprogress->m_sl9.SetRange(0,1000);
  1525.           inprogress->m_sl10.SetRange(0,1000);
  1526.           inprogress->m_sl11.SetRange(0,1000);
  1527.           inprogress->m_sl12.SetRange(0,1000);
  1528.           inprogress->m_sl13.SetRange(0,1000);
  1529.           
  1530.           if (!parsing)
  1531.             inprogress->m_sl0.SetPos(StatsBuffer[0].offset);
  1532.           inprogress->m_sl1.SetPos(StatsBuffer[1].offset);
  1533.           inprogress->m_sl2.SetPos(StatsBuffer[2].offset);
  1534.           inprogress->m_sl3.SetPos(StatsBuffer[3].offset);
  1535.           inprogress->m_sl4.SetPos(StatsBuffer[4].offset);
  1536.           inprogress->m_sl5.SetPos(StatsBuffer[5].offset);
  1537.           inprogress->m_sl6.SetPos(StatsBuffer[6].offset);
  1538.           inprogress->m_sl7.SetPos(StatsBuffer[7].offset);
  1539.           inprogress->m_sl8.SetPos(StatsBuffer[8].offset);
  1540.           inprogress->m_sl9.SetPos(StatsBuffer[9].offset);
  1541.           inprogress->m_sl10.SetPos(StatsBuffer[10].offset);
  1542.           inprogress->m_sl11.SetPos(StatsBuffer[11].offset);
  1543.           inprogress->m_sl12.SetPos(StatsBuffer[12].offset);
  1544.           inprogress->m_sl13.SetPos(StatsBuffer[13].offset);
  1545.           
  1546.           // redraw en boucle
  1547.           {
  1548.             int i=0;
  1549.             if (parsing)
  1550.               i++;
  1551.             for( ; i<NStatsBuffer;i++) {
  1552.               CString st;
  1553.               st = StatsBuffer[i].etat;
  1554.               st.Replace("&", "&&");
  1555.               SetWindowTextCP(inprogress->element[0][i], st);
  1556.               st = StatsBuffer[i].nom;
  1557.               st.Replace("&", "&&");
  1558.               SetWindowTextCP(inprogress->element[1][i], st);
  1559.               st = StatsBuffer[i].fichier;
  1560.               st.Replace("&", "&&");
  1561.               SetWindowTextCP(inprogress->element[4][i], st);
  1562.               
  1563.               if ((strlen(StatsBuffer[i].etat)==0) != StatsBuffer[i].actived) {
  1564.                 StatsBuffer[i].actived=!StatsBuffer[i].actived;
  1565.                 if (!StatsBuffer[i].actived)
  1566.                   inprogress->element[3][i]->ModifyStyle(WS_DISABLED,0);
  1567.                 else
  1568.                   inprogress->element[3][i]->ModifyStyle(0,WS_DISABLED);
  1569.                 inprogress->element[3][i]->RedrawWindow();
  1570.               }
  1571.             }
  1572.           }
  1573.           //
  1574.         }
  1575.         /* else*/
  1576.         if (parsing) {  // parsing
  1577.           //
  1578.           inprogress->m_sl0.SetRange(0,100);
  1579.           inprogress->m_sl0.SetPos(parsing);
  1580.           SetWindowTextCP(inprogress->element[0][0], LANG(LANG_F14 /*"scanning","parcours"*/));
  1581.           SetWindowTextCP(inprogress->element[1][0], StatsBuffer[0].nom);
  1582.           SetWindowTextCP(inprogress->element[4][0], "");
  1583.           //inprogress->element[0][1]->SetWindowTextCP(this, );
  1584.         }
  1585.         
  1586.       }
  1587.       {
  1588.         static char last_info[256]="";
  1589.         char info[256];
  1590.         if ((SInfo.stat_nsocket==-1)) {
  1591. #if USE_RAS
  1592.           if (!has_started)
  1593. #endif
  1594.             SetDlgItemTextCP(inprogress, IDC_nm0,LANG(LANG_F15 /*"Waiting for specific hour to start","Attente de l'heure programmΘe pour dΘmarrer"*/));
  1595. #if USE_RAS
  1596.           else
  1597.             SetDlgItemTextCP(inprogress, IDC_nm0,LANG(LANG_F16 /*"Connecting to provider","Connexion au provider"*/));
  1598. #endif
  1599.           inprogress->m_sl0.SetRange(0,SInfo.ft);
  1600.           inprogress->m_sl0.SetPos(SInfo.ft-SInfo.stat_time);  // temps restant
  1601.           // SetDlgItemTextCP(inprogress, IDC_nm1,_SN(ft));
  1602.           if (icn && (!this_CSplitterFrame->iconifie)) {  // minimisΘe mais pas en icone
  1603.             sprintf(info,"[%d s]",SInfo.stat_time);
  1604.           } else {
  1605.             sprintf(info,LANG(LANG_F17 /*"Mirror waiting [%d seconds]","Miroir en attente [%d secondes]"*/),SInfo.stat_time);
  1606.           }
  1607.         } else {
  1608.           if (icn) {  // minimisΘe
  1609.             sprintf(info,"[%s]",lnk);
  1610.           } else {
  1611.             char byteb[256];
  1612.             sprintf(byteb, LLintP, SInfo.stat_bytes);
  1613.             sprintf(info,LANG(LANG_F18),lnk,byteb);
  1614.           }
  1615.         }
  1616.         if (strcmp(info,last_info)) {       /* a changΘ */
  1617.           strcpybuff(last_info,info);           /* recopier */
  1618.           if (this_CSplitterFrame->iconifie)  // minimisΘ icone
  1619.             this_CSplitterFrame->IconChange(last_info);
  1620.           else
  1621.             SetWindowTextCP(GetMainWindow(), last_info);
  1622.         }
  1623.       }  
  1624.       
  1625.       //inprogress->UpdateWindow();
  1626.     } else {
  1627.     }
  1628.   }
  1629.   // WHTT_UNLOCK();
  1630.   return 1;
  1631. }
  1632.  
  1633. /* Plantages si DoModal() dans un thread != du principal.. passons.. */
  1634. const char* __cdecl httrackengine_query(t_hts_callbackarg *carg, httrackp *opt, const char* question) {
  1635.   strcpybuff(WIZ_question,question);
  1636.   strcpybuff(WIZ_reponse, "");
  1637.   // AfxGetMainWnd()
  1638.   CWnd* wnd = GetMainWindow();
  1639.   if (wnd) {
  1640.     wnd->SendMessage(WM_COMMAND,wm_WizRequest1,0);
  1641.   }
  1642.   return WIZ_reponse;
  1643. }
  1644.  
  1645. const char* __cdecl httrackengine_query2(t_hts_callbackarg *carg, httrackp *opt, const char* question) {
  1646.   strcpybuff(WIZ_question,question);
  1647.   strcpybuff(WIZ_reponse, "");
  1648.   // AfxGetMainWnd()
  1649.   CWnd* wnd = GetMainWindow();
  1650.   if (wnd) {
  1651.     wnd->SendMessage(WM_COMMAND,wm_WizRequest2,0);
  1652.   }
  1653.   return WIZ_reponse;
  1654. }
  1655.  
  1656. const char* __cdecl httrackengine_query3(t_hts_callbackarg *carg, httrackp *opt, const char* question) {
  1657.   strcpybuff(WIZ_question,question);
  1658.   strcpybuff(WIZ_reponse, "");
  1659.   CWnd* wnd = GetMainWindow();
  1660.   if (wnd) {
  1661.     wnd->SendMessage(WM_COMMAND,wm_WizRequest3,0);
  1662.   }
  1663.   return WIZ_reponse;
  1664. }
  1665.  
  1666. void __cdecl httrackengine_pause(t_hts_callbackarg *carg, httrackp *opt, const char* lockfile) {
  1667.   ATLTRACE(__FUNCTION__ " : pause\r\n");
  1668.   AfxMessageBox("Engine paused.. click OK to continue!",MB_OK);
  1669.   remove(lockfile);
  1670. }
  1671.  
  1672. // modif RX 10/10/98 pour gestion des , et des tabs
  1673. static void StripControls(char* chaine)
  1674. {
  1675.   for(int i=0 ; chaine[i] != '\0' ; i++)
  1676.   {
  1677.     if(chaine[i]=='\n' || chaine[i]==13 || chaine[i]==9) {
  1678.       chaine[i]=' ';
  1679.     }
  1680.   }
  1681. }
  1682.  
  1683. #if SHELL_MULTITHREAD
  1684.  
  1685. static int __cdecl ExcFilter_(DWORD dwExceptCode, PEXCEPTION_POINTERS pExceptPtrs) {
  1686.   return EXCEPTION_CONTINUE_EXECUTION;
  1687. }                              
  1688.  
  1689. void __cdecl RunBackRobot(void* al_p) {
  1690.   int argc;
  1691.   char** argv;
  1692.  
  1693.   while((!inprogress) && (!termine)) Sleep(10);
  1694.   if (inprogress)
  1695.     while ((!inprogress->m_hWnd) || (termine)) Sleep(10);   // attendre formulaire
  1696.     //Sleep(100);
  1697.     
  1698.     Robot_params* al=(Robot_params*) al_p;
  1699.     argc = al->argc;
  1700.     argv = al->argv;
  1701.     /* launch the engine */
  1702.     hts_init();
  1703. #ifndef _DEBUG
  1704.     __try
  1705. #endif
  1706.         {
  1707.             if (global_opt != NULL)
  1708.             {
  1709.                 hts_free_opt(global_opt);
  1710.                 global_opt = NULL;
  1711.             }
  1712.       global_opt = hts_create_opt();
  1713.  
  1714.       CHAIN_FUNCTION(global_opt, init, httrackengine_init, NULL);
  1715.       CHAIN_FUNCTION(global_opt, uninit, httrackengine_uninit, NULL);
  1716.       CHAIN_FUNCTION(global_opt, start, httrackengine_start, NULL);
  1717.       CHAIN_FUNCTION(global_opt, end, httrackengine_end, NULL);
  1718.       CHAIN_FUNCTION(global_opt, chopt, httrackengine_chopt, NULL);
  1719.       CHAIN_FUNCTION(global_opt, preprocess, httrackengine_htmlpreprocess, NULL);
  1720.       CHAIN_FUNCTION(global_opt, postprocess, httrackengine_htmlpostprocess, NULL);
  1721.       CHAIN_FUNCTION(global_opt, check_html, httrackengine_htmlcheck, NULL);
  1722.       CHAIN_FUNCTION(global_opt, query, httrackengine_query, NULL);
  1723.       CHAIN_FUNCTION(global_opt, query2, httrackengine_query2, NULL);
  1724.       CHAIN_FUNCTION(global_opt, query3, httrackengine_query3, NULL);
  1725.       CHAIN_FUNCTION(global_opt, loop, httrackengine_loop, NULL);
  1726.       CHAIN_FUNCTION(global_opt, check_link, httrackengine_check, NULL);
  1727.       CHAIN_FUNCTION(global_opt, check_mime, httrackengine_check_mime, NULL);
  1728.       CHAIN_FUNCTION(global_opt, pause, httrackengine_pause, NULL);
  1729.       CHAIN_FUNCTION(global_opt, filesave, httrackengine_filesave, NULL);
  1730.       CHAIN_FUNCTION(global_opt, filesave2, httrackengine_filesave2, NULL);
  1731.       
  1732.             HTTRACK_result = hts_main2(argc, argv, global_opt);
  1733.     }
  1734. #ifndef _DEBUG
  1735.     __except(ExcFilter_(GetExceptionCode(), GetExceptionInformation()))
  1736.     {
  1737.       HTTRACK_result = -100;
  1738.     }
  1739. #endif
  1740.     /* clear all vars */
  1741.     WHTT_LOCK();
  1742.     termine=1;
  1743.     WHTT_UNLOCK();
  1744.     htsthread_wait_n(1);
  1745.     hts_uninit();
  1746. }
  1747. #endif
  1748.  
  1749. // modifs RX 10/10/98: gestion des ,
  1750. CString change(char* chaine,char c) {
  1751.   int comma=1; int first=1;
  1752.   CString chaine1;
  1753.   for(int i=0;i < (int) strlen(chaine);i++) {
  1754.     switch(chaine[i]) {
  1755.     case 10: case 13: case 9: case ' ': case ',':
  1756.       comma=1; 
  1757.       break;
  1758.     default:
  1759.       if (comma) {
  1760.         if (!first) chaine1 +=' ';
  1761.         else first=0; 
  1762.         chaine1  +=c; 
  1763.         comma=0;
  1764.       }
  1765.       chaine1 += chaine[i]; 
  1766.       break;
  1767.     }
  1768.   }
  1769.   return chaine1;
  1770. }
  1771.  
  1772.  
  1773. // Lancement
  1774. void lance(void) {
  1775.   char **argv;
  1776.   int argvAlloc = 1024;
  1777.   int argc=1;
  1778.   int g=0;
  1779.   int i =0;
  1780.     char catbuff[CATBUFF_SIZE], catbuff2[CATBUFF_SIZE];
  1781.   
  1782.   //
  1783.   if (fp_debug) {
  1784.     fprintf(fp_debug,"Building command line\r\n");
  1785.     fflush(fp_debug);
  1786.   }
  1787.   //
  1788.   ShellOptions->LINE = "";
  1789.   ShellOptions->LINE = "-";
  1790.   if (ShellOptions->choixdeb[0]!='W')
  1791.     ShellOptions->LINE += "q";         // quiet
  1792.   
  1793.   if (ShellOptions->choixdeb[0]=='/')
  1794.     ShellOptions->LINE += "i";
  1795.   else if (ShellOptions->choixdeb[0]!='!')
  1796.     ShellOptions->LINE += ShellOptions->choixdeb;
  1797.   // option de profondeur
  1798.   if(strcmp(ShellOptions->depth,"")!=0) { 
  1799.     ShellOptions->LINE += "r";
  1800.     ShellOptions->LINE += ShellOptions->depth;
  1801.   }
  1802.   if(strcmp(ShellOptions->extdepth,"")!=0) { 
  1803.     ShellOptions->LINE += "%e";
  1804.     ShellOptions->LINE += ShellOptions->extdepth;
  1805.   }
  1806.   if(strcmp(ShellOptions->cache,"")!=0) ShellOptions->LINE += ShellOptions->cache;
  1807.   if(strcmp(ShellOptions->norecatch,"")!=0) ShellOptions->LINE += ShellOptions->norecatch;
  1808.   if(strcmp(ShellOptions->testall,"")!=0) ShellOptions->LINE += ShellOptions->testall;
  1809.   if(strcmp(ShellOptions->parseall,"")!=0) ShellOptions->LINE += ShellOptions->parseall;
  1810.   if(strcmp(ShellOptions->link,"")!=0) ShellOptions->LINE += ShellOptions->link;
  1811.   if(strcmp(ShellOptions->external,"")!=0) ShellOptions->LINE += ShellOptions->external;
  1812.   if(strcmp(ShellOptions->nopurge,"")!=0) ShellOptions->LINE += ShellOptions->nopurge;
  1813.   if(strcmp(ShellOptions->hidepwd,"")!=0) ShellOptions->LINE += ShellOptions->hidepwd;
  1814.   if(strcmp(ShellOptions->hidequery,"")!=0) ShellOptions->LINE += ShellOptions->hidequery;
  1815.   if(strcmp(ShellOptions->robots,"")!=0) ShellOptions->LINE += ShellOptions->robots;
  1816.   if(strcmp(ShellOptions->cookies,"")!=0) ShellOptions->LINE += ShellOptions->cookies;
  1817.   if(strcmp(ShellOptions->checktype,"")!=0) ShellOptions->LINE += ShellOptions->checktype;
  1818.   if(strcmp(ShellOptions->parsejava,"")!=0) ShellOptions->LINE += ShellOptions->parsejava;
  1819.   if(strcmp(ShellOptions->Cache2,"")!=0) ShellOptions->LINE += ShellOptions->Cache2;
  1820.   if(strcmp(ShellOptions->logtype,"")!=0) ShellOptions->LINE += ShellOptions->logtype;
  1821.   if (ShellOptions->http10.GetLength()) ShellOptions->LINE += ShellOptions->http10;
  1822.   if (ShellOptions->toler.GetLength()) ShellOptions->LINE += ShellOptions->toler;
  1823.   if (ShellOptions->updhack.GetLength()) ShellOptions->LINE += ShellOptions->updhack;
  1824.   if (ShellOptions->urlhack.GetLength()) ShellOptions->LINE += ShellOptions->urlhack;
  1825.   
  1826.   // si get, ne pas faire
  1827.   if (strcmp(ShellOptions->choixdeb,"g")!=0) {
  1828.     if(ShellOptions->build[0]=='-') {
  1829.       ShellOptions->LINE += " ";
  1830.       ShellOptions->LINE += ShellOptions->build;
  1831.       ShellOptions->LINE += " -";
  1832.     } else if (strcmp(ShellOptions->build,"")!=0) ShellOptions->LINE += ShellOptions->build;
  1833.   }
  1834.   ShellOptions->LINE += ShellOptions->dos;
  1835.   ShellOptions->LINE += ShellOptions->index;
  1836.   ShellOptions->LINE += ShellOptions->index2;
  1837.   ShellOptions->LINE += ShellOptions->htmlfirst;
  1838.   ShellOptions->LINE += ShellOptions->filtre;
  1839.   ShellOptions->LINE += ShellOptions->max;
  1840.   ShellOptions->LINE += ShellOptions->frag;
  1841.   ShellOptions->LINE += ShellOptions->maxfile;
  1842.   ShellOptions->LINE += ShellOptions->conn;
  1843.   ShellOptions->LINE += ShellOptions->time;
  1844.   ShellOptions->LINE += ShellOptions->rate;
  1845.   ShellOptions->LINE += ShellOptions->retry;
  1846.   ShellOptions->LINE += ShellOptions->hostquit;
  1847.   ShellOptions->LINE += ShellOptions->ka;
  1848.   ShellOptions->LINE += ShellOptions->log;
  1849.   ShellOptions->LINE += ShellOptions->errpage;
  1850.   //-->
  1851.   ShellOptions->LINE += ShellOptions->waittime;
  1852.   ShellOptions->LINE += ShellOptions->maxtime;
  1853.   ShellOptions->LINE += ShellOptions->maxrate;
  1854.   ShellOptions->LINE += ShellOptions->maxconn;
  1855.   ShellOptions->LINE += ShellOptions->maxlinks;
  1856.   ShellOptions->LINE += ShellOptions->proxyftp;  
  1857.   ShellOptions->LINE += "#f";  // flush
  1858.   
  1859.   if (strcmp(ShellOptions->user,"")!=0) {ShellOptions->LINE += " ";ShellOptions->LINE += "-F";ShellOptions->LINE += " ";ShellOptions->LINE += ShellOptions->user;}
  1860.   if (strcmp(ShellOptions->footer,"")!=0) {ShellOptions->LINE += " ";ShellOptions->LINE += "-%F";ShellOptions->LINE += " ";ShellOptions->LINE += ShellOptions->footer;}
  1861.   
  1862.   if ((int)ShellOptions->proxy.GetLength()>0) {
  1863.     ShellOptions->LINE += " -P ";
  1864.     ShellOptions->LINE += ShellOptions->proxy;
  1865.     ShellOptions->LINE += ":";
  1866.     ShellOptions->LINE += ShellOptions->port;
  1867.   }
  1868.   
  1869.   if (strnotempty(LANGUAGE_ISO)) {
  1870.     ShellOptions->LINE += " -%l \"";
  1871.     ShellOptions->LINE += LANGUAGE_ISO;
  1872.     if (LANGUAGE_ISO != "en")
  1873.       ShellOptions->LINE += ", en";
  1874.     ShellOptions->LINE += ", *\"";
  1875.   }
  1876.   
  1877.   // mode spider, mettre aprΦs options
  1878.   if (ShellOptions->choixdeb[0]=='!') {
  1879.     ShellOptions->LINE += " --testlinks";
  1880.   } else if (ShellOptions->choixdeb[0]=='Y') {
  1881.     ShellOptions->LINE += " --mirrorlinks";
  1882.   }
  1883.   
  1884.   // URLs!!
  1885.   ShellOptions->LINE += " ";
  1886.   ShellOptions->LINE += ShellOptions->url;
  1887.   
  1888.   // file list
  1889.   if ((int) ShellOptions->filelist.GetLength()>0) {
  1890.     ShellOptions->LINE += " -%L \"";
  1891.     ShellOptions->LINE += ShellOptions->filelist;
  1892.     ShellOptions->LINE += "\"";
  1893.   }
  1894.   
  1895.   // chemins
  1896.   if(ShellOptions->path != "") {
  1897.     ShellOptions->LINE += " ";
  1898.     ShellOptions->LINE += "-O1";
  1899.     ShellOptions->LINE += " ";
  1900.     ShellOptions->LINE += ShellOptions->path;
  1901.   }
  1902.   
  1903.   // buffer -> les + et -
  1904.   if(strcmp(ShellOptions->buff_filtres,"")!=0) {
  1905.     //if(strcmp(diafiltre.m_url2 ,"")!=0) {
  1906.     ShellOptions->LINE += " ";
  1907.     ShellOptions->LINE += ShellOptions->buff_filtres ;
  1908.   }
  1909.   
  1910.   // --assume
  1911.   if (strnotempty(ShellOptions->buff_MIME)) {
  1912.     ShellOptions->LINE += " ";
  1913.     ShellOptions->LINE += ShellOptions->buff_MIME ;
  1914.   }
  1915.   
  1916.   // ---
  1917.   
  1918.   //
  1919.   if (fp_debug) {
  1920.     fprintf(fp_debug,"Cleaning up command line and counting parameters\r\n");
  1921.     fflush(fp_debug);
  1922.   }
  1923.   //
  1924.   // Θpurer cr,lf,tab - double espace -> espace
  1925.   {
  1926.     char *a;
  1927.     while(a=strchr(ShellOptions->LINE,9)) *a=' ';
  1928.     while(a=strchr(ShellOptions->LINE,10)) *a=' ';
  1929.     while(a=strchr(ShellOptions->LINE,13)) *a=' ';
  1930.   }
  1931.   
  1932.   ShellOptions->LINE_back = ShellOptions->LINE;
  1933.   
  1934.   // couper en morceaux
  1935.   {
  1936.     char* p=ShellOptions->LINE.GetBuffer(0);
  1937.     argv = (char**) malloct(argvAlloc * sizeof(char*));
  1938.     argv[0]="winhttrack";
  1939.     do {
  1940.       if (argc >= argvAlloc) {
  1941.         argvAlloc *= 2;
  1942.         argv = (char**) realloct(argv, argvAlloc * sizeof(char*));
  1943.         assertf(argv != NULL);
  1944.       }
  1945.       argv[argc++]=p;
  1946.       p=next_token(p,0);    // prochain token
  1947.       if (p) {
  1948.         *p=0;    // octet nul (tableau)
  1949.         p++;
  1950.       }            
  1951.     } while(p!=NULL);
  1952.   }
  1953.   
  1954.   //
  1955.   if (fp_debug) {
  1956.     fprintf(fp_debug,"Checking doit.log\r\n");
  1957.     fflush(fp_debug);
  1958.   }
  1959.   //
  1960.   // Ok, on lance!
  1961.   if(!termine) {
  1962.     int result=0;
  1963.     {
  1964.       char path_log[HTS_URLMAXSIZE*2];
  1965.       strcpybuff(path_log,CShellApp_app->end_path_complete);
  1966.       if (strlen(path_log)>0)
  1967.         if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  1968.           strcatbuff(path_log,"/");
  1969.         
  1970.         // on efface le doit.log, pour annuler les parametres anciens et en redΘfinir de nouveaux
  1971.         // c'est ici une logique qui diffΦre de la version en ligne de commande
  1972.         if (fexist(fconcat(catbuff,path_log,"hts-cache/new.zip"))
  1973.           || fexist(fconcat(catbuff2,path_log,"hts-cache/new.ndx"))
  1974.           ) {    // un cache est prΘsent
  1975.           if (fexist(fconcat(catbuff,path_log,"hts-cache/doit.log")))
  1976.             remove(fconcat(catbuff,path_log,"hts-cache/doit.log"));
  1977.           FILE* fp=fopen(fconcat(catbuff,path_log,"hts-cache/doit.log"),"wb");
  1978.           if (fp) fclose(fp);
  1979.         }
  1980.         //}
  1981.     }
  1982.     
  1983.     
  1984.     // ---
  1985.     // LANCER LE MIROIR
  1986.     // ---
  1987.     //
  1988.     if (fp_debug) {
  1989.       fprintf(fp_debug,"Ready to call httrack engine, launching threads\r\n");
  1990.       fflush(fp_debug);
  1991.     }
  1992.     //
  1993. #if SHELL_MULTITHREAD
  1994.     Robot_params al;
  1995.     al.argc=argc;
  1996.     al.argv=argv;
  1997.     hts_newthread( RunBackRobot, (void*) &al);
  1998.     
  1999.     //
  2000.     if (fp_debug) {
  2001.       fprintf(fp_debug,"Threads launched, displaying main dialog\r\n");
  2002.       fflush(fp_debug);
  2003.     }
  2004.     //
  2005.     // domodal du refresh
  2006.     /* XXC A SUPPRIMER */
  2007.     while(!termine) {
  2008.       Sleep(100);
  2009.     }
  2010.     //inprogress->DoModal();
  2011.     WHTT_LOCK();
  2012.     shell_terminated=1;
  2013.     result=HTTRACK_result;
  2014.     termine=1;  
  2015.     WHTT_UNLOCK();
  2016.     //
  2017.     if (fp_debug) {
  2018.       fprintf(fp_debug,"Main dialog exited\r\n");
  2019.       fflush(fp_debug);
  2020.     }
  2021.     //
  2022.     
  2023.     // non multithread
  2024. #else
  2025. #error "Non supportΘ"
  2026. #endif
  2027.  
  2028.     /* Aborted mirror or finished? */
  2029.     {
  2030.       char path_log[HTS_URLMAXSIZE*2];
  2031.       strcpybuff(path_log,CShellApp_app->end_path_complete);
  2032.       if (strlen(path_log)>0)
  2033.         if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  2034.           strcatbuff(path_log,"/");
  2035.         if (soft_term_requested || termine_requested) {
  2036.           FILE* fp=fopen(fconcat(catbuff,path_log,"hts-cache/interrupted.lock"),"wb");
  2037.           if (fp)
  2038.             fclose(fp);
  2039.         } else
  2040.           remove(fconcat(catbuff,path_log,"hts-cache/interrupted.lock"));
  2041.     }
  2042.     
  2043.     //SetForegroundWindow();   // yop en premier plan!
  2044.     //
  2045.     if (fp_debug) {
  2046.       fprintf(fp_debug,"Displaying end dialog\r\n");
  2047.       fflush(fp_debug);
  2048.     }
  2049.     //
  2050.     /* New pannel */
  2051.     if (result) {      // erreur?
  2052.       strcpybuff(end_mirror_msg,LANG(LANG_F19 /*"A problem occured during the mirror\n  \"","Un problΦme est survenu pendant le miroir\n  \""*/));
  2053.       strcatbuff(end_mirror_msg,"\"");
  2054.       if (result != -100) {
  2055.         strcatbuff(end_mirror_msg,hts_errmsg(global_opt));
  2056.       } else {
  2057.                 strcatbuff(end_mirror_msg, "The engine unexpectedly crashed.");
  2058.       }
  2059.       strcatbuff(end_mirror_msg,"\"");
  2060.       strcatbuff(end_mirror_msg,LANG(LANG_F20 /*"\" \nDuring:\n  ","\" \nDurant:\n  "*/));
  2061.       strcatbuff(end_mirror_msg,"\"");
  2062.       strcatbuff(end_mirror_msg,ShellOptions->LINE_back);
  2063.       strcatbuff(end_mirror_msg,"\"");
  2064.       strcatbuff(end_mirror_msg,LANG(LANG_F21 /*"\nSee the log file if necessary.\n\nClick OK to quit WinHTTrack.\n\nThanks for using WinHTTrack!","\nVoir le fichier log au besoin\n\nCliquez sur OK pour quitter WinHTTrack\n\nMerci d'utiliser WinHTTrack."*/));
  2065.       //AfxMessageBox(s,MB_OK+MB_ICONINFORMATION);
  2066.     } else {
  2067.       strcpybuff(end_mirror_msg,LANG(LANG_F22 /*"The mirror is finished.\nClick OK to quit WinHTTrack.\nSee log file(s) if necessary to ensure that everything is OK.\n\nThanks for using WinHTTrack!","Le miroir est terminΘ\nCliquez sur OK pour quitter WinHTTrack\nVoir au besoin les fichiers d'audit pour vΘrifier que tout s'est bien passΘ\n\nMerci d'utiliser WinHTTrack!"*/));
  2068.       //AfxMessageBox("The mirror is finished.\nClic OK to quit WinHTTrack.\nSee log file(s) if necessary to ensure that everything is OK.\n\nThanks for using WinHTTrack!",MB_OK+MB_ICONINFORMATION);
  2069.       //        ShellExecute(0,"open",,"","",);
  2070.     }
  2071. #if USE_RAS
  2072.     // erreur ras
  2073.     if (connected == -1)
  2074.       if ((int) strlen(connected_err) > 0)
  2075.         strcpybuff(end_mirror_msg,connected_err);
  2076. #endif
  2077.       {
  2078.         char pathlog[HTS_URLMAXSIZE*2];
  2079.         strcpybuff(pathlog,dialog0->GetPath());
  2080.         Ciplog form;
  2081.         if (strlen(pathlog)>0)
  2082.           if ((pathlog[strlen(pathlog)-1]!='/') && (pathlog[strlen(pathlog)-1]!='\\'))
  2083.             strcatbuff(pathlog,"/");
  2084.           // fichier log existe ou on est tΘlΘcommandΘ par un !
  2085.           if ( (fsize(fconcat(catbuff,pathlog,"hts-err.txt")))>0) {
  2086.             strcatbuff(end_mirror_msg,LANG(LANG_F23 /*"\n\nTip: Click [View log file] to see warning or error messages","\n\nConseil: [Voir fichiers log] pour voir les erreurs et messages"*/));
  2087.           }
  2088.       }
  2089.       //this_Cinfoend->m_infoend = msg;
  2090.       inprogress->SendMessage(WM_USER + 4);      // avertir
  2091.       if (fp_debug) {
  2092.         fprintf(fp_debug,"DoModal end dialog, waiting\r\n");
  2093.         fflush(fp_debug);
  2094.       }
  2095.       /*
  2096.       if (info.DoModal() == IDC_NewProject) {     // relancer programme!
  2097.       // copie de onnewproject() de wid1::
  2098.       CWinApp* pApp = AfxGetApp();
  2099.       CString name = pApp->m_pszHelpFilePath;
  2100.       name=name.Left(name.GetLength()-4);
  2101.       name += ".EXE";
  2102.       ShellExecute(NULL,"open",name,"","",SW_RESTORE);    
  2103.       }
  2104.       */
  2105.       if (fp_debug) {
  2106.         fprintf(fp_debug,"Final info OK, leaving..\r\n");
  2107.         fflush(fp_debug);
  2108.       }
  2109.   }
  2110.   else {
  2111.   }
  2112.  
  2113.   if (argv != NULL)
  2114.     freet(argv);
  2115.   
  2116. }
  2117.  
  2118. // int LANG_T(int);
  2119. // char* LANG(char* english,char* francais);
  2120.  
  2121.  
  2122. /* interface lang - lang_string="stringlang0\nstringlang1\n..laststring" */
  2123. void SetCombo(CWnd* _this,int id,char* lang_string) {
  2124.   CComboBox* combo = (CComboBox*) _this->GetDlgItem(id);
  2125.   CString st=lang_string;
  2126.   st.TrimLeft(); st.TrimRight();
  2127.   if (combo) {
  2128.     st+="\n";         /* end */
  2129.     combo->ResetContent();
  2130.     while(st.GetLength()) {
  2131.       int pos=st.Find('\n');
  2132.       CString item=st.Left(pos);
  2133.       st=st.Mid(pos+1);
  2134.       item.TrimLeft(); item.TrimRight();
  2135.       if (item.GetLength())
  2136.         combo->AddString(item);
  2137.     }
  2138.   }
  2139. }
  2140.  
  2141.  
  2142. // Ecriture profiles
  2143. CString profile_code(char* from) {
  2144.   int i;
  2145.   CString result;
  2146.   for(i = 0 ; from[i] != '\0' ; i++) {
  2147.     switch(from[i]) {
  2148.     case '%': 
  2149.       result += '%';
  2150.       result += '%';
  2151.       break;
  2152.     case '=': 
  2153.       result += '%';
  2154.       result += '3';
  2155.       result += 'd';
  2156.       break;
  2157.     case 13:
  2158.       result += '%';
  2159.       result += '0';
  2160.       result += 'd';
  2161.       break;
  2162.     case 10:
  2163.       result += '%';
  2164.       result += '0';
  2165.       result += 'a';
  2166.       break;
  2167.     case 9:
  2168.       result += '%';
  2169.       result += '0';
  2170.       result += '9';
  2171.       break;
  2172.     default:
  2173.       result += from[i];
  2174.       break;
  2175.     }
  2176.   }
  2177.   return result;
  2178. }
  2179. CString profile_decode(char* from) {
  2180.   int j;
  2181.   CString result;
  2182.   for(j = 0 ; from[j] != '\0' ; ) {  // oui oui
  2183.     if (from[j]=='%') {
  2184.       if (from[j + 1] == '%') {
  2185.         result += '%';
  2186.         j+=2;
  2187.       } else {
  2188.         if (strncmp(from+j+1,"0d", 2)==0)
  2189.           result += (char) 13;
  2190.         else if (strncmp(from+j+1,"0a", 2)==0)
  2191.           result += (char) 10;
  2192.         else if (strncmp(from+j+1,"09", 2)==0)
  2193.           result += (char) 9;
  2194.         else if (strncmp(from+j+1,"3d", 2)==0)
  2195.           result += '=';
  2196.         else
  2197.           result += ' ';
  2198.         j+=3;
  2199.       }
  2200.     } else
  2201.       result += from[j++];
  2202.   }
  2203.   return result;
  2204. }
  2205. //
  2206. // Ecriture/Lecture profiles
  2207. int MyWriteProfileInt(CString path,CString dummy,CString name,int value) {
  2208.   if (path.IsEmpty()) {
  2209.     CWinApp* pApp = AfxGetApp();
  2210.     pApp->WriteProfileInt(dummy,name,value);
  2211.   } else if (path=="<mem>") {       // buffer
  2212.     tmpm.setInt(name,value);
  2213.     return 0;
  2214.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2215.     if (tmpf) {
  2216.       return MyWriteProfileIntFile(tmpf,dummy,name,value);
  2217.     }
  2218.   } else {
  2219.     FILE* fp = fopen(path,"ab");
  2220.     if (fp) {
  2221.       int r=MyWriteProfileIntFile(fp,dummy,name,value);
  2222.       /*
  2223.       fprintf(fp,"%s=%d\x0d\x0a",name,value);
  2224.       */
  2225.       fclose(fp);
  2226.       return r;
  2227.     }
  2228.   }
  2229.   return 0;
  2230. }
  2231. int MyWriteProfileIntFile(FILE* fp,CString dummy,CString name,int value) {
  2232.   if (fp) {
  2233.     fprintf(fp,"%s=%d\x0d\x0a", name, value);
  2234.   }
  2235.   return 0;
  2236. }
  2237. int MyWriteProfileString(CString path,CString dummy,CString name,CString value) {
  2238.   if (path.IsEmpty()) {
  2239.     CWinApp* pApp = AfxGetApp();
  2240.     pApp->WriteProfileString(dummy, name, profile_code(value.GetBuffer(0)));
  2241.   } else if (path=="<mem>") {       // buffer
  2242.     tmpm.setString(name,value);
  2243.     return 0;
  2244.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2245.     if (tmpf) {
  2246.       return MyWriteProfileStringFile(tmpf,dummy,name,value);
  2247.     }
  2248.   } else {
  2249.     FILE* fp = fopen(path,"ab");
  2250.     if (fp) {
  2251.       int r=MyWriteProfileStringFile(fp,dummy,name,value);
  2252.       fclose(fp);
  2253.       return r;
  2254.     }
  2255.   }
  2256.   return 0;
  2257. }
  2258. int MyWriteProfileStringFile(FILE* fp,CString dummy,CString name,CString value) {
  2259.   if (fp) {
  2260.     fprintf(fp,"%s=%s\x0d\x0a", name, profile_code(value.GetBuffer(0)).GetBuffer(0));
  2261.   }
  2262.   return 0;
  2263. }
  2264. //
  2265. // lecture
  2266. int MyGetProfileInt(CString path,CString dummy,CString name,int value) {
  2267.   if (path.IsEmpty()) {
  2268.     CWinApp* pApp = AfxGetApp();
  2269.     return pApp->GetProfileInt(dummy, name, value);
  2270.   } else if (path=="<mem>") {       // buffer
  2271.     return tmpm.getInt(name,value);
  2272.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2273.     if (tmpf) {
  2274.       return MyGetProfileIntFile(tmpf,dummy,name,value);
  2275.     } else return value;
  2276.   } else {
  2277.     FILE* fp = fopen(path,"rb");
  2278.     if (fp) {
  2279.       int r=MyGetProfileIntFile(fp,dummy,name,value);
  2280.       fclose(fp);
  2281.       return r;
  2282.     } else return value;
  2283.   }
  2284. }
  2285. int MyGetProfileIntFile(FILE* fp,CString dummy,CString name,int value) {
  2286.   if (fp) {
  2287.     char srch[256];
  2288.     fseek(fp,0,SEEK_SET);
  2289.     sprintf(srch,"%s=",name);
  2290.     while(!feof(fp)) {
  2291.       char s[2048]; s[0]='\0';
  2292.       linput(fp,s,2000);
  2293.       if (strlen(s)==0)     // EOF
  2294.         return value;
  2295.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2296.         int val;
  2297.         if (sscanf(s+strlen(srch),"%d",&val) == 1)
  2298.           return val;
  2299.         else
  2300.           return value;
  2301.       }
  2302.     }
  2303.     return value;
  2304.   } else return value;
  2305. }
  2306. CString MyGetProfileString(CString path,CString dummy,CString name,CString value) {
  2307.   if (path.IsEmpty()) {
  2308.     CWinApp* pApp = AfxGetApp();
  2309.     return profile_decode(pApp->GetProfileString(dummy, name, profile_code(value.GetBuffer(0)).GetBuffer(0)).GetBuffer(0));
  2310.   } else if (path=="<mem>") {       // buffer
  2311.     return tmpm.getString(name,value);
  2312.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2313.     if (tmpf) {
  2314.       return MyGetProfileStringFile(tmpf,dummy,name,value);
  2315.     } else return value;
  2316.   } else {
  2317.     FILE* fp = fopen(path,"rb");
  2318.     if (fp) {
  2319.       CString st=MyGetProfileStringFile(fp,dummy,name,value);
  2320.       fclose(fp);
  2321.       return st;
  2322.     } else return value;
  2323.   }
  2324. }
  2325. CString MyGetProfileStringFile(FILE* fp,CString dummy,CString name,CString value) {
  2326.   if (fp) {
  2327.     char srch[256];
  2328.     fseek(fp,0,SEEK_SET);
  2329.     sprintf(srch,"%s",name);
  2330.     strcatbuff(srch,"=");
  2331.     while(!feof(fp)) {
  2332.       char s[32768]; s[0]='\0';
  2333.       linput(fp,s,32000);
  2334.       if (strlen(s)==0)     // EOF
  2335.         return value;
  2336.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2337.         return profile_decode(s+strlen(srch));
  2338.       }
  2339.     }
  2340.     return value;
  2341.   } else return value;
  2342. }
  2343.  
  2344. //
  2345. // Get_profile et Write_profile eux mΩmes
  2346. //
  2347. // path="" -> Θcrire dans la base (default)
  2348. // path="<tmp>" -> Θcrire dans le fichier tempo commun
  2349. // path="<mem>" -> Θcrire dans le buffer tempo commun
  2350. // path="<null>" -> lire default (illΘgal en Θcriture)
  2351. void Write_profile(CString path,int load_path) {
  2352.   CWaitCursor wait;
  2353.   CString strSection       = "OptionsValues";
  2354.   CString st;
  2355.   int n;
  2356.   
  2357.   // Fichier tempo ou fichier?
  2358.   if (path=="<tmp>") {     // fichier temporaire
  2359.     if (tmpf)
  2360.       fclose(tmpf);
  2361.     tmpf=tmpfile();
  2362.     if (!tmpf)
  2363.       return;
  2364.   } else if (path=="<mem>") {     // buffer temporaire
  2365.     tmpm.deleteAll();
  2366.   } else if (!(path.IsEmpty())) {
  2367.     FILE *fp=fopen(path,"wb");
  2368.     if (fp) 
  2369.       fclose(fp);
  2370.   }
  2371.   
  2372.   //if (dialog3.m_hWnd == NULL) {    // pas initialisΘ
  2373.   if (maintab->m_hWnd == NULL) {    // pas initialisΘ
  2374.     // checkboxes
  2375.     MyWriteProfileInt(path,strSection, "Near",maintab->m_option1.m_link);
  2376.     MyWriteProfileInt(path,strSection, "Test",maintab->m_option1.m_testall);
  2377.     MyWriteProfileInt(path,strSection, "ParseAll",maintab->m_option1.m_parseall);
  2378.     MyWriteProfileInt(path,strSection, "HTMLFirst",maintab->m_option1.m_htmlfirst);
  2379.     MyWriteProfileInt(path,strSection, "Cache",maintab->m_option3.m_cache);
  2380.     MyWriteProfileInt(path,strSection, "NoRecatch",maintab->m_option9.m_norecatch);
  2381.     MyWriteProfileInt(path,strSection, "Dos",
  2382.       ((maintab->m_option2.m_dos)?1:0)
  2383.       +
  2384.       (((maintab->m_option2.m_iso9660)?1:0)<<1)
  2385.       );
  2386.     MyWriteProfileInt(path,strSection, "Index",maintab->m_option9.m_index);
  2387.     MyWriteProfileInt(path,strSection, "WordIndex",maintab->m_option9.m_index2);
  2388.     MyWriteProfileInt(path,strSection, "Log",maintab->m_option9.m_logf);
  2389.     MyWriteProfileInt(path,strSection, "RemoveTimeout",maintab->m_option4.m_remt);
  2390.     MyWriteProfileInt(path,strSection, "RemoveRateout",maintab->m_option4.m_rems);
  2391.     MyWriteProfileInt(path,strSection, "KeepAlive",maintab->m_option4.m_ka);
  2392.     MyWriteProfileInt(path,strSection, "FollowRobotsTxt",maintab->m_option8.m_robots);
  2393.     MyWriteProfileInt(path,strSection, "NoErrorPages",maintab->m_option2.m_errpage);
  2394.     MyWriteProfileInt(path,strSection, "NoExternalPages",maintab->m_option2.m_external);
  2395.     MyWriteProfileInt(path,strSection, "NoPwdInPages",maintab->m_option2.m_hidepwd);
  2396.     MyWriteProfileInt(path,strSection, "NoQueryStrings",maintab->m_option2.m_hidequery);
  2397.     MyWriteProfileInt(path,strSection, "NoPurgeOldFiles",maintab->m_option2.m_nopurge);
  2398.     MyWriteProfileInt(path,strSection, "Cookies",maintab->m_option8.m_cookies);
  2399.     MyWriteProfileInt(path,strSection, "CheckType",maintab->m_option8.m_checktype);
  2400.     MyWriteProfileInt(path,strSection, "ParseJava",maintab->m_option8.m_parsejava);
  2401.     MyWriteProfileInt(path,strSection, "HTTP10",maintab->m_option8.m_http10);
  2402.     MyWriteProfileInt(path,strSection, "TolerantRequests",maintab->m_option8.m_toler);
  2403.     MyWriteProfileInt(path,strSection, "UpdateHack",maintab->m_option8.m_updhack);
  2404.     MyWriteProfileInt(path,strSection, "URLHack",maintab->m_option8.m_urlhack);
  2405.     MyWriteProfileInt(path,strSection, "StoreAllInCache",maintab->m_option9.m_Cache2);
  2406.     MyWriteProfileInt(path,strSection, "LogType",maintab->m_option9.m_logtype);
  2407.     MyWriteProfileInt(path,strSection, "UseHTTPProxyForFTP",maintab->m_option10.m_ftpprox);
  2408.     
  2409.     // menus
  2410.     MyWriteProfileInt(path,strSection, "Build",maintab->m_option2.m_build);
  2411.     MyWriteProfileInt(path,strSection, "PrimaryScan",maintab->m_option3.m_filter);
  2412.     MyWriteProfileInt(path,strSection, "Travel",maintab->m_option3.m_travel);
  2413.     MyWriteProfileInt(path,strSection, "GlobalTravel",maintab->m_option3.m_travel2);
  2414.     MyWriteProfileInt(path,strSection, "RewriteLinks",maintab->m_option3.m_travel3);
  2415.     MyWriteProfileString(path,strSection, "BuildString",maintab->m_option2.Bopt.m_BuildString);
  2416.     
  2417.     // champs
  2418.     MyWriteProfileString(path,strSection, "Category", this_CSplitterFrame->GetCurrentCategory());
  2419.  
  2420.     MyWriteProfileString(path,strSection, "MaxHtml",maintab->m_option5.m_maxhtml);
  2421.     MyWriteProfileString(path,strSection, "MaxOther",maintab->m_option5.m_othermax);
  2422.     MyWriteProfileString(path,strSection, "MaxAll",maintab->m_option5.m_sizemax);
  2423.     MyWriteProfileString(path,strSection, "MaxWait",maintab->m_option5.m_pausebytes);
  2424.     MyWriteProfileString(path,strSection, "Sockets",maintab->m_option4.m_connexion);
  2425.     MyWriteProfileString(path,strSection, "Retry",maintab->m_option4.m_retry);
  2426.     MyWriteProfileString(path,strSection, "MaxTime",maintab->m_option5.m_maxtime);
  2427.     MyWriteProfileString(path,strSection, "TimeOut",maintab->m_option4.m_timeout);
  2428.     MyWriteProfileString(path,strSection, "RateOut",maintab->m_option4.m_rate);
  2429.     MyWriteProfileString(path,strSection, "UserID",maintab->m_option6.m_user);
  2430.     MyWriteProfileString(path,strSection, "Footer",maintab->m_option6.m_footer);
  2431.     MyWriteProfileString(path,strSection, "MaxRate",maintab->m_option5.m_maxrate);
  2432.     MyWriteProfileString(path,strSection, "WildCardFilters",maintab->m_option7.m_url2);
  2433.     MyWriteProfileString(path,strSection, "Proxy",maintab->m_option10.m_proxy);
  2434.     MyWriteProfileString(path,strSection, "Port",maintab->m_option10.m_port);
  2435.     MyWriteProfileString(path,strSection, "Depth",maintab->m_option5.m_depth);
  2436.     MyWriteProfileString(path,strSection, "ExtDepth",maintab->m_option5.m_depth2);
  2437.     MyWriteProfileString(path,strSection, "MaxConn",maintab->m_option5.m_maxconn);    
  2438.     MyWriteProfileString(path,strSection, "MaxLinks",maintab->m_option5.m_maxlinks);    
  2439.     
  2440.     // 11
  2441.     MyWriteProfileString(path,strSection, "MIMEDefsExt1",maintab->m_option11.m_ext1);    
  2442.     MyWriteProfileString(path,strSection, "MIMEDefsExt2",maintab->m_option11.m_ext2);    
  2443.     MyWriteProfileString(path,strSection, "MIMEDefsExt3",maintab->m_option11.m_ext3);    
  2444.     MyWriteProfileString(path,strSection, "MIMEDefsExt4",maintab->m_option11.m_ext4);    
  2445.     MyWriteProfileString(path,strSection, "MIMEDefsExt5",maintab->m_option11.m_ext5);    
  2446.     MyWriteProfileString(path,strSection, "MIMEDefsExt6",maintab->m_option11.m_ext6);    
  2447.     MyWriteProfileString(path,strSection, "MIMEDefsExt7",maintab->m_option11.m_ext7);    
  2448.     MyWriteProfileString(path,strSection, "MIMEDefsExt8",maintab->m_option11.m_ext8);    
  2449.     MyWriteProfileString(path,strSection, "MIMEDefsMime1",maintab->m_option11.m_mime1);    
  2450.     MyWriteProfileString(path,strSection, "MIMEDefsMime2",maintab->m_option11.m_mime2);    
  2451.     MyWriteProfileString(path,strSection, "MIMEDefsMime3",maintab->m_option11.m_mime3);    
  2452.     MyWriteProfileString(path,strSection, "MIMEDefsMime4",maintab->m_option11.m_mime4);    
  2453.     MyWriteProfileString(path,strSection, "MIMEDefsMime5",maintab->m_option11.m_mime5);    
  2454.     MyWriteProfileString(path,strSection, "MIMEDefsMime6",maintab->m_option11.m_mime6);    
  2455.     MyWriteProfileString(path,strSection, "MIMEDefsMime7",maintab->m_option11.m_mime7);    
  2456.     MyWriteProfileString(path,strSection, "MIMEDefsMime8",maintab->m_option11.m_mime8);
  2457.   } else {
  2458.     st = this_CSplitterFrame->GetCurrentCategory(); MyWriteProfileString(path,strSection,"Category",st);
  2459.  
  2460.     // checkboxes
  2461.     // 1
  2462.     n=maintab->m_option1.IsDlgButtonChecked(IDC_link);
  2463.     MyWriteProfileInt(path,strSection,"Near", n);
  2464.     n=maintab->m_option1.IsDlgButtonChecked(IDC_testall);
  2465.     MyWriteProfileInt(path,strSection,"Test", n);
  2466.     n=maintab->m_option1.IsDlgButtonChecked(IDC_parseall);
  2467.     MyWriteProfileInt(path,strSection,"ParseAll", n);
  2468.     n=maintab->m_option1.IsDlgButtonChecked(IDC_htmlfirst);
  2469.     MyWriteProfileInt(path,strSection,"HTMLFirst", n);
  2470.     // 2
  2471.     n=maintab->m_option3.IsDlgButtonChecked(IDC_Cache);
  2472.     MyWriteProfileInt(path,strSection,"Cache", n);
  2473.     n=maintab->m_option2.IsDlgButtonChecked(IDC_norecatch);
  2474.     MyWriteProfileInt(path,strSection,"NoRecatch", n);
  2475.     n = ((maintab->m_option2.IsDlgButtonChecked(IDC_dos))?1:0)
  2476.       + ((maintab->m_option2.IsDlgButtonChecked(IDC_iso9660)?1:0)<<1);
  2477.     MyWriteProfileInt(path,strSection,"Dos", n);
  2478.     n=maintab->m_option2.IsDlgButtonChecked(IDC_index);
  2479.     MyWriteProfileInt(path,strSection,"Index", n);
  2480.     n=maintab->m_option2.IsDlgButtonChecked(IDC_index2);
  2481.     MyWriteProfileInt(path,strSection,"WordIndex", n);
  2482.     n=maintab->m_option2.IsDlgButtonChecked(IDC_logf);
  2483.     MyWriteProfileInt(path,strSection,"Log", n);
  2484.     n=maintab->m_option2.IsDlgButtonChecked(IDC_errpage);
  2485.     MyWriteProfileInt(path,strSection,"NoErrorPages", n);
  2486.     n=maintab->m_option2.IsDlgButtonChecked(IDC_hidepwd);
  2487.     MyWriteProfileInt(path,strSection,"NoPwdInPages", n);
  2488.     n=maintab->m_option2.IsDlgButtonChecked(IDC_hidequery);
  2489.     MyWriteProfileInt(path,strSection,"NoQueryStrings", n);
  2490.     n=maintab->m_option2.IsDlgButtonChecked(IDC_external);
  2491.     MyWriteProfileInt(path,strSection,"NoExternalPages", n);
  2492.     n=maintab->m_option2.IsDlgButtonChecked(IDC_nopurge);
  2493.     MyWriteProfileInt(path,strSection,"NoPurgeOldFiles", n);
  2494.     if ((n=maintab->m_option2.m_ctl_build.GetCurSel()) != CB_ERR)
  2495.       MyWriteProfileInt(path,strSection, "Build", n);
  2496.     st = maintab->m_option2.Bopt.m_BuildString;
  2497.     if (st.GetLength()>0)
  2498.       MyWriteProfileString(path,strSection, "BuildString",st);
  2499.     // 3
  2500.     // menus
  2501.     if ((n=maintab->m_option3.m_ctl_filter.GetCurSel()) != CB_ERR)
  2502.       MyWriteProfileInt(path,strSection, "PrimaryScan", n);
  2503.     if ((n=maintab->m_option3.m_ctl_travel.GetCurSel()) != CB_ERR)
  2504.       MyWriteProfileInt(path,strSection, "Travel", n);
  2505.     if ((n=maintab->m_option3.m_ctl_travel2.GetCurSel()) != CB_ERR)
  2506.       MyWriteProfileInt(path,strSection, "GlobalTravel", n);
  2507.     if ((n=maintab->m_option3.m_ctl_travel3.GetCurSel()) != CB_ERR)
  2508.       MyWriteProfileInt(path,strSection, "RewriteLinks", n);
  2509.     //
  2510.     maintab->m_option8.GetDlgItemText(IDC_robots,st);
  2511.     MyWriteProfileString(path,strSection, "FollowRobotsTxt", st);
  2512.     // 4
  2513.     maintab->m_option4.GetDlgItemText(IDC_connexion,st);
  2514.     MyWriteProfileString(path,strSection, "Sockets", st);
  2515.     maintab->m_option4.GetDlgItemText(IDC_timeout,st);
  2516.     MyWriteProfileString(path,strSection, "TimeOut", st);
  2517.     n=maintab->m_option4.IsDlgButtonChecked(IDC_remt);
  2518.     MyWriteProfileInt(path,strSection,"RemoveTimeout", n);
  2519.     maintab->m_option4.GetDlgItemText(IDC_retry,st);
  2520.     MyWriteProfileString(path,strSection, "Retry", st);
  2521.     maintab->m_option4.GetDlgItemText(IDC_rate,st);
  2522.     MyWriteProfileString(path,strSection, "RateOut", st);
  2523.     n=maintab->m_option4.IsDlgButtonChecked(IDC_rems);
  2524.     MyWriteProfileInt(path,strSection,"RemoveRateout", n);
  2525.     n=maintab->m_option4.IsDlgButtonChecked(IDC_ka);
  2526.     MyWriteProfileInt(path,strSection,"KeepAlive", n);
  2527.     // 5
  2528.     maintab->m_option5.GetDlgItemText(IDC_maxhtml,st);
  2529.     MyWriteProfileString(path,strSection, "MaxHtml", st);
  2530.     maintab->m_option5.GetDlgItemText(IDC_othermax,st);
  2531.     MyWriteProfileString(path,strSection, "MaxOther", st);
  2532.     maintab->m_option5.GetDlgItemText(IDC_sizemax,st);
  2533.     MyWriteProfileString(path,strSection, "MaxAll", st);
  2534.     maintab->m_option5.GetDlgItemText(IDC_pausebytes,st);
  2535.     MyWriteProfileString(path,strSection, "MaxWait", st);
  2536.     maintab->m_option5.GetDlgItemText(IDC_maxtime,st);
  2537.     MyWriteProfileString(path,strSection, "MaxTime", st);
  2538.     maintab->m_option5.GetDlgItemText(IDC_maxrate,st);
  2539.     MyWriteProfileString(path,strSection, "MaxRate", st);
  2540.     maintab->m_option5.GetDlgItemText(IDC_depth,st);
  2541.     MyWriteProfileString(path,strSection,"Depth",st);
  2542.     maintab->m_option5.GetDlgItemText(IDC_depth2,st);
  2543.     MyWriteProfileString(path,strSection,"ExtDepth",st);
  2544.     maintab->m_option5.GetDlgItemText(IDC_maxconn,st);
  2545.     MyWriteProfileString(path,strSection, "MaxConn", st);
  2546.     maintab->m_option5.GetDlgItemText(IDC_maxlinks,st);
  2547.     MyWriteProfileString(path,strSection, "MaxLinks", st);
  2548.     // 6
  2549.     maintab->m_option6.GetDlgItemText(IDC_user,st);
  2550.     MyWriteProfileString(path,strSection, "UserID", st);
  2551.     maintab->m_option6.GetDlgItemText(IDC_footer,st);
  2552.     MyWriteProfileString(path,strSection, "Footer", st);
  2553.     // 7
  2554.     maintab->m_option7.GetDlgItemText(IDC_URL2,st);
  2555.     MyWriteProfileString(path,strSection, "WildCardFilters", st);
  2556.     // 8
  2557.     maintab->m_option8.GetDlgItemText(IDC_cookies,st);
  2558.     MyWriteProfileString(path,strSection, "Cookies", st);
  2559.     maintab->m_option8.GetDlgItemText(IDC_checktype,st);
  2560.     MyWriteProfileString(path,strSection, "CheckType", st);
  2561.     n=maintab->m_option8.IsDlgButtonChecked(IDC_parsejava);
  2562.     MyWriteProfileInt(path,strSection, "ParseJava", n);
  2563.     n=maintab->m_option8.IsDlgButtonChecked(IDC_http10);
  2564.     MyWriteProfileInt(path,strSection, "HTTP10", n);
  2565.     n=maintab->m_option8.IsDlgButtonChecked(IDC_toler);
  2566.     MyWriteProfileInt(path,strSection, "TolerantRequests", n);
  2567.     n=maintab->m_option8.IsDlgButtonChecked(IDC_updhack);
  2568.     MyWriteProfileInt(path,strSection, "UpdateHack", n);
  2569.     n=maintab->m_option8.IsDlgButtonChecked(IDC_urlhack);
  2570.     MyWriteProfileInt(path,strSection, "URLHack", n);
  2571.     // 9
  2572.     maintab->m_option9.GetDlgItemText(IDC_Cache2,st);
  2573.     MyWriteProfileString(path,strSection, "StoreAllInCache", st);
  2574.     maintab->m_option9.GetDlgItemText(IDC_logtype,st);
  2575.     MyWriteProfileString(path,strSection, "LogType", st);
  2576.     // 10
  2577.     maintab->m_option10.GetDlgItemText(IDC_prox,st);
  2578.     MyWriteProfileString(path,strSection,"Proxy",st);
  2579.     maintab->m_option10.GetDlgItemText(IDC_proxport,st);
  2580.     MyWriteProfileString(path,strSection,"Port",st);
  2581.     n=maintab->m_option10.IsDlgButtonChecked(IDC_ftpprox);
  2582.     MyWriteProfileInt(path,strSection,"UseHTTPProxyForFTP", n);
  2583.     
  2584.     // 11
  2585.     maintab->m_option11.GetDlgItemText(IDC_ext1,st); MyWriteProfileString(path,strSection,"MIMEDefsExt1",st);
  2586.     maintab->m_option11.GetDlgItemText(IDC_ext2,st); MyWriteProfileString(path,strSection,"MIMEDefsExt2",st);
  2587.     maintab->m_option11.GetDlgItemText(IDC_ext3,st); MyWriteProfileString(path,strSection,"MIMEDefsExt3",st);
  2588.     maintab->m_option11.GetDlgItemText(IDC_ext4,st); MyWriteProfileString(path,strSection,"MIMEDefsExt4",st);
  2589.     maintab->m_option11.GetDlgItemText(IDC_ext5,st); MyWriteProfileString(path,strSection,"MIMEDefsExt5",st);
  2590.     maintab->m_option11.GetDlgItemText(IDC_ext6,st); MyWriteProfileString(path,strSection,"MIMEDefsExt6",st);
  2591.     maintab->m_option11.GetDlgItemText(IDC_ext7,st); MyWriteProfileString(path,strSection,"MIMEDefsExt7",st);
  2592.     maintab->m_option11.GetDlgItemText(IDC_ext8,st); MyWriteProfileString(path,strSection,"MIMEDefsExt8",st);
  2593.     maintab->m_option11.GetDlgItemText(IDC_mime1,st); MyWriteProfileString(path,strSection,"MIMEDefsMime1",st);
  2594.     maintab->m_option11.GetDlgItemText(IDC_mime2,st); MyWriteProfileString(path,strSection,"MIMEDefsMime2",st);
  2595.     maintab->m_option11.GetDlgItemText(IDC_mime3,st); MyWriteProfileString(path,strSection,"MIMEDefsMime3",st);
  2596.     maintab->m_option11.GetDlgItemText(IDC_mime4,st); MyWriteProfileString(path,strSection,"MIMEDefsMime4",st);
  2597.     maintab->m_option11.GetDlgItemText(IDC_mime5,st); MyWriteProfileString(path,strSection,"MIMEDefsMime5",st);
  2598.     maintab->m_option11.GetDlgItemText(IDC_mime6,st); MyWriteProfileString(path,strSection,"MIMEDefsMime6",st);
  2599.     maintab->m_option11.GetDlgItemText(IDC_mime7,st); MyWriteProfileString(path,strSection,"MIMEDefsMime7",st);
  2600.     maintab->m_option11.GetDlgItemText(IDC_mime8,st); MyWriteProfileString(path,strSection,"MIMEDefsMime8",st);
  2601.   }
  2602.   // liens, jokers etc. si mirror merge
  2603.   if (!(path.IsEmpty())) {
  2604.     if (dialog1->m_hWnd == NULL) {    // pas initialisΘ
  2605.       //MyWriteProfileString(path,strSection,"CurrentDepth",dialog1->m_depth);
  2606.       MyWriteProfileString(path,strSection,"CurrentUrl",dialog1->m_urls);
  2607.       if (dialog1->m_todo >= 0)
  2608.         MyWriteProfileInt(path, strSection,"CurrentAction", dialog1->m_todo);
  2609.       //
  2610.       MyWriteProfileString(path,strSection,"CurrentURLList",dialog1->m_filelist);
  2611.       
  2612.       //if (load_path) {
  2613.       //MyWriteProfileString(path,strSection,"CurrentPath1",dialog0->GetPath());
  2614.       //MyWriteProfileString(path,strSection,"CurrentPath2",dialog0->GetPath());
  2615.       //}
  2616.     } else {
  2617.       //dialog1->GetDlgItemText(IDC_depth,st);
  2618.       //MyWriteProfileString(path,strSection,"CurrentDepth",st);
  2619.       dialog1->GetDlgItemText(IDC_URL,st);
  2620.       MyWriteProfileString(path,strSection,"CurrentUrl",st);
  2621.       if ((n=dialog1->m_ctl_todo.GetCurSel()) != CB_ERR)
  2622.         MyWriteProfileInt(path,strSection, "CurrentAction", n);
  2623.       //
  2624.       dialog1->GetDlgItemText(IDC_filelist,st);
  2625.       MyWriteProfileString(path,strSection,"CurrentURLList",st);
  2626.       //
  2627.       //if (load_path) {
  2628.       //dialog1->GetDlgItemText(IDC_pathlog,st);
  2629.       //MyWriteProfileString(path,strSection,"CurrentPath1",st);
  2630.       //dialog1->GetDlgItemText(IDC_pthmir,st);
  2631.       //MyWriteProfileString(path,strSection,"CurrentPath2",st);
  2632.       //}
  2633.     }
  2634.   }
  2635. }
  2636. // path="" -> lire dans la base (default)
  2637. //if not exist: do not load anything but patches projname&co
  2638. void Read_profile(CString path,int load_path) {
  2639.   CWaitCursor wait;
  2640.   CString strSection       = "OptionsValues";
  2641.   CString st;
  2642.   
  2643.   // VΘrification <tmp>
  2644.   if (path=="<tmp>") {     // fichier temporaire
  2645.     if (!tmpf)
  2646.       return;
  2647.     else
  2648.       fflush(tmpf);
  2649.   } else if (path=="<null>") {     // options par dΘfaut
  2650.     path="<mem>";
  2651.     tmpm.deleteAll();              // effacer
  2652.   } else {
  2653.     int pos=path.ReverseFind('\\');
  2654.     if (pos>=0) {
  2655.       CString dir=path.Left(pos);           // enlever winprofile.ini
  2656.       pos=dir.ReverseFind('\\');
  2657.       if (pos>=0) {
  2658.         dir=dir.Left(pos);                  // enlever hts-cache
  2659.         pos=dir.ReverseFind('\\');
  2660.         if (pos>=0) {
  2661.           dialog0->m_projname=dir.Mid(pos+1);
  2662.           dialog0->m_projpath=dir.Left(pos);
  2663.           /*
  2664.           if (this_CWizTab)
  2665.           this_CWizTab->SetActivePage(2);     // page 3
  2666.           */
  2667.         }
  2668.       }
  2669.     }
  2670.   }
  2671.   
  2672.   // checkboxes
  2673.   maintab->m_option1.m_link      = MyGetProfileInt(path,strSection, "Near",0);
  2674.   maintab->m_option1.m_testall   = MyGetProfileInt(path,strSection, "Test",0);
  2675.   maintab->m_option1.m_parseall  = MyGetProfileInt(path,strSection, "ParseAll",1);
  2676.   maintab->m_option1.m_htmlfirst = MyGetProfileInt(path,strSection, "HTMLFirst",0);
  2677.   maintab->m_option3.m_cache     = MyGetProfileInt(path,strSection, "Cache",1);
  2678.   maintab->m_option9.m_norecatch = MyGetProfileInt(path,strSection, "NoRecatch",0);
  2679.   maintab->m_option2.m_dos       = (MyGetProfileInt(path,strSection, "Dos",0) & 1);
  2680.   maintab->m_option2.m_iso9660   = ((MyGetProfileInt(path,strSection, "Dos",0) & 2)>>1);
  2681.   maintab->m_option9.m_index     = MyGetProfileInt(path,strSection, "Index",1);
  2682.   maintab->m_option9.m_index2    = MyGetProfileInt(path,strSection, "WordIndex",0);
  2683.   maintab->m_option9.m_logf      = MyGetProfileInt(path,strSection, "Log",1);
  2684.   maintab->m_option4.m_remt      = MyGetProfileInt(path,strSection, "RemoveTimeout",0);
  2685.   maintab->m_option4.m_rems      = MyGetProfileInt(path,strSection, "RemoveRateout",0);
  2686.   maintab->m_option4.m_ka        = MyGetProfileInt(path,strSection, "KeepAlive",1);
  2687.   maintab->m_option8.m_robots    = MyGetProfileInt(path,strSection, "FollowRobotsTxt",2);
  2688.   maintab->m_option2.m_errpage   = MyGetProfileInt(path,strSection, "NoErrorPages",0);
  2689.   maintab->m_option2.m_external  = MyGetProfileInt(path,strSection, "NoExternalPages",0);
  2690.   maintab->m_option2.m_hidepwd   = MyGetProfileInt(path,strSection, "NoPwdInPages",0);
  2691.   maintab->m_option2.m_hidequery = MyGetProfileInt(path,strSection, "NoQueryStrings",0);
  2692.   maintab->m_option2.m_nopurge   = MyGetProfileInt(path,strSection, "NoPurgeOldFiles",0);
  2693.   maintab->m_option8.m_cookies    = MyGetProfileInt(path,strSection, "Cookies",1);
  2694.   maintab->m_option8.m_checktype  = MyGetProfileInt(path,strSection, "CheckType",1);
  2695.   maintab->m_option8.m_parsejava  = MyGetProfileInt(path,strSection, "ParseJava",1);
  2696.   maintab->m_option8.m_toler      = MyGetProfileInt(path,strSection, "TolerantRequests",0);
  2697.   maintab->m_option8.m_updhack    = MyGetProfileInt(path,strSection, "UpdateHack",1);
  2698.   maintab->m_option8.m_urlhack    = MyGetProfileInt(path,strSection, "URLHack",1);
  2699.   maintab->m_option8.m_http10     = MyGetProfileInt(path,strSection, "HTTP10",0);
  2700.   maintab->m_option9.m_Cache2     = MyGetProfileInt(path,strSection, "StoreAllInCache",0);
  2701.   maintab->m_option9.m_logtype    = MyGetProfileInt(path,strSection, "LogType",0);
  2702.   
  2703.   // menus
  2704.   maintab->m_option2.m_build   = MyGetProfileInt(path,strSection, "Build",0);
  2705.   maintab->m_option3.m_filter  = MyGetProfileInt(path,strSection, "PrimaryScan",3);
  2706.   maintab->m_option3.m_travel  = MyGetProfileInt(path,strSection, "Travel",1);
  2707.   maintab->m_option3.m_travel2 = MyGetProfileInt(path,strSection, "GlobalTravel",0);
  2708.   maintab->m_option3.m_travel3 = MyGetProfileInt(path,strSection, "RewriteLinks",0);
  2709.   maintab->m_option2.Bopt.m_BuildString = MyGetProfileString(path,strSection, "BuildString","%h%p/%n%q.%t");
  2710.   
  2711.   // champs
  2712.   dialog0->m_projcateg =          MyGetProfileString(path,strSection, "Category");
  2713.  
  2714.   maintab->m_option5.m_maxhtml =  MyGetProfileString(path,strSection, "MaxHtml");
  2715.   maintab->m_option5.m_othermax=  MyGetProfileString(path,strSection, "MaxOther");
  2716.   maintab->m_option5.m_sizemax =  MyGetProfileString(path,strSection, "MaxAll");
  2717.   maintab->m_option5.m_pausebytes=MyGetProfileString(path,strSection, "MaxWait");  
  2718.   maintab->m_option4.m_connexion= MyGetProfileString(path,strSection, "Sockets");
  2719.   maintab->m_option4.m_retry   =  MyGetProfileString(path,strSection, "Retry");
  2720.   maintab->m_option5.m_maxtime =  MyGetProfileString(path,strSection, "MaxTime");
  2721.   maintab->m_option4.m_timeout =  MyGetProfileString(path,strSection, "TimeOut");
  2722.   maintab->m_option4.m_rate    =  MyGetProfileString(path,strSection, "RateOut");
  2723.   maintab->m_option6.m_user    =  MyGetProfileString(path,strSection, "UserID","Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98)");
  2724.   maintab->m_option6.m_footer  =  MyGetProfileString(path,strSection, "Footer",HTS_DEFAULT_FOOTER);
  2725.   maintab->m_option5.m_maxrate =  MyGetProfileString(path,strSection, "MaxRate", "25000");
  2726.   maintab->m_option5.m_maxconn =  MyGetProfileString(path,strSection, "MaxConn");
  2727.   maintab->m_option5.m_maxlinks = MyGetProfileString(path,strSection, "MaxLinks");
  2728.   
  2729.   // 7
  2730.   maintab->m_option7.m_url2 = MyGetProfileString(path,strSection, "WildCardFilters","+*.png +*.gif +*.jpg +*.css +*.js -ad.doubleclick.net/* -mime:application/foobar");
  2731.   
  2732.   // 10
  2733.   maintab->m_option10.m_proxy   = MyGetProfileString(path,strSection, "Proxy");
  2734.   maintab->m_option10.m_port    = MyGetProfileString(path,strSection, "Port");
  2735.   maintab->m_option10.m_ftpprox = MyGetProfileInt(path,strSection, "UseHTTPProxyForFTP",1);
  2736.   //
  2737.   maintab->m_option5.m_depth    = MyGetProfileString(path,strSection, "Depth");
  2738.   maintab->m_option5.m_depth2   = MyGetProfileString(path,strSection, "ExtDepth");
  2739.   
  2740.   // 11
  2741.   maintab->m_option11.m_ext1   = MyGetProfileString(path,strSection, "MIMEDefsExt1");   // php3,php,php2,asp,jsp,pl,cfm,nsf
  2742.   maintab->m_option11.m_ext2   = MyGetProfileString(path,strSection, "MIMEDefsExt2");
  2743.   maintab->m_option11.m_ext3   = MyGetProfileString(path,strSection, "MIMEDefsExt3");
  2744.   maintab->m_option11.m_ext4   = MyGetProfileString(path,strSection, "MIMEDefsExt4");
  2745.   maintab->m_option11.m_ext5   = MyGetProfileString(path,strSection, "MIMEDefsExt5");
  2746.   maintab->m_option11.m_ext6   = MyGetProfileString(path,strSection, "MIMEDefsExt6");
  2747.   maintab->m_option11.m_ext7   = MyGetProfileString(path,strSection, "MIMEDefsExt7");
  2748.   maintab->m_option11.m_ext8   = MyGetProfileString(path,strSection, "MIMEDefsExt8");
  2749.   maintab->m_option11.m_mime1   = MyGetProfileString(path,strSection, "MIMEDefsMime1");   // text/html
  2750.   maintab->m_option11.m_mime2   = MyGetProfileString(path,strSection, "MIMEDefsMime2");
  2751.   maintab->m_option11.m_mime3   = MyGetProfileString(path,strSection, "MIMEDefsMime3");
  2752.   maintab->m_option11.m_mime4   = MyGetProfileString(path,strSection, "MIMEDefsMime4");
  2753.   maintab->m_option11.m_mime5   = MyGetProfileString(path,strSection, "MIMEDefsMime5");
  2754.   maintab->m_option11.m_mime6   = MyGetProfileString(path,strSection, "MIMEDefsMime6");
  2755.   maintab->m_option11.m_mime7   = MyGetProfileString(path,strSection, "MIMEDefsMime7");
  2756.   maintab->m_option11.m_mime8   = MyGetProfileString(path,strSection, "MIMEDefsMime8");
  2757.   
  2758.   
  2759.   //st = MyGetProfileString(path,strSection,"WildCardFilters");
  2760.   //ShellOptions->buff_filtres = st;
  2761.   
  2762.   // liens, jokers etc. si mirror merge
  2763.   if (!(path.IsEmpty())) {
  2764.     if (dialog1->m_hWnd == NULL) {    // pas initialisΘ
  2765.       //dialog1->m_depth  = MyGetProfileString(path,strSection,"CurrentDepth");
  2766.       dialog1->m_urls     = MyGetProfileString(path,strSection,"CurrentUrl");
  2767.       dialog1->m_todo     = MyGetProfileInt(path,strSection,"CurrentAction",0);
  2768.       dialog1->m_filelist = MyGetProfileString(path,strSection,"CurrentURLList");
  2769.       /*
  2770.       if (load_path) {
  2771.       CString st;
  2772.       st = MyGetProfileString(path,strSection,"CurrentPath1");
  2773.       if (st != "")
  2774.       dialog1->m_pathlog = st;
  2775.       st = MyGetProfileString(path,strSection,"CurrentPath2");
  2776.       if (st != "")
  2777.       dialog1->m_pathmir = st;
  2778.       }
  2779.       */
  2780.     } else {
  2781.       //st = MyGetProfileString(path,strSection,"CurrentDepth");
  2782.       //dialog1->SetDlgItemText(IDC_depth,st);
  2783.       st = MyGetProfileString(path,strSection,"CurrentUrl");
  2784.       SetDlgItemTextCP(dialog1, IDC_URL,st);
  2785.       int n = MyGetProfileInt(path,strSection,"CurrentAction",0);
  2786.       dialog1->m_ctl_todo.SetCurSel(n);
  2787.       st = MyGetProfileString(path,strSection,"CurrentURLList");
  2788.       SetDlgItemTextCP(dialog1, IDC_filelist,st);
  2789.       /*
  2790.       if (load_path) {
  2791.       st = MyGetProfileString(path,strSection,"CurrentPath1");
  2792.       if (st != "")
  2793.       dialog1->SetDlgItemText(IDC_pathlog,st);
  2794.       st = MyGetProfileString(path,strSection,"CurrentPath2");
  2795.       if (st != "")
  2796.       dialog1->SetDlgItemText(IDC_pthmir,st);
  2797.       }
  2798.       */
  2799.       dialog1->Refresh();
  2800.     }
  2801.   }
  2802.   
  2803. }
  2804.  
  2805. // Initialisation du RAS
  2806. void InitRAS() {
  2807. #if USE_RAS
  2808.   if (!LibRas) {
  2809.     LibRas=new CDynamicRAS();
  2810.     if (LibRas->IsRASLoaded()) 
  2811.       LibRasUse=1;
  2812.     else
  2813.       LibRasUse=0;
  2814.   }
  2815. #endif
  2816. }
  2817.  
  2818. // Reconstruire index gΘnΘral!
  2819. void Build_TopIndex(BOOL check_empty) {
  2820.   CWaitCursor wait;
  2821.  
  2822.   //if (toptemplate_header && toptemplate_body && toptemplate_footer) {
  2823.   {
  2824.     TStamp t_start = mtime_local();
  2825.     char path[HTS_URLMAXSIZE*2];
  2826.     strcpybuff(path,CShellApp_app->end_path);
  2827.  
  2828.     /* Build top index */
  2829.     httrackp *opt = hts_create_opt();
  2830.     TStamp t_opt = mtime_local();
  2831.     opt->log = opt->errlog = NULL;
  2832.     hts_buildtopindex(opt,path, "");
  2833.     hts_free_opt(opt);
  2834.     TStamp t_build = mtime_local();
  2835.  
  2836.     /* Check empty dirs and build .whtt */
  2837.     // FILE* fpo=fopen(fconcat(path,"/index.html"),"wb");
  2838.     //if (fpo) {
  2839.     {
  2840.       // verif_backblue(opt, path);    // gΘnΘrer gif
  2841.       //
  2842.       // Header
  2843.       //fprintf(fpo,toptemplate_header,
  2844.       //  "<!-- Mirror and index made by HTTrack Website Copier/"HTTRACK_VERSION" "HTTRACK_AFF_AUTHORS" -->"
  2845.       //  );
  2846.       // chargement de la liste
  2847.       WIN32_FIND_DATA find;
  2848.       HANDLE h = FindFirstFile(CShellApp_app->end_path+"*.*",&find);
  2849.       if (h != INVALID_HANDLE_VALUE) {
  2850.         CString to_delete="";
  2851.         do {
  2852.           if (!(find.dwFileAttributes  & (FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN) ))
  2853.             if (strcmp(find.cFileName,".."))
  2854.               if (strcmp(find.cFileName,"."))
  2855.                 if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2856.                   int r;
  2857.                   r=CheckDirInfo(CShellApp_app->end_path+find.cFileName);
  2858.                   if ((r>=0) && (r<=3)) {       /* vide, fichiers vides etc */
  2859.                     to_delete+=(CShellApp_app->end_path+find.cFileName+"\n");
  2860.                   } else {      /* non vide */
  2861.                     char iname[HTS_URLMAXSIZE*2],iname2[HTS_URLMAXSIZE*2];
  2862.                     strcpybuff(iname,CShellApp_app->end_path);
  2863.                     strcatbuff(iname,find.cFileName);
  2864.                     strcatbuff(iname,"\\");
  2865.                     strcpybuff(iname2,iname);
  2866.                     strcatbuff(iname,"index.html");
  2867.                     strcatbuff(iname2,"\\hts-cache\\winprofile.ini");
  2868.                     if (fexist(iname)) {
  2869.                       char hname[HTS_URLMAXSIZE*2];
  2870.                       strcpybuff(hname,find.cFileName);
  2871.                       escape_check_url(hname);
  2872.                       // Body
  2873.                       //fprintf(fpo,toptemplate_body,
  2874.                       //  hname,
  2875.                       //  find.cFileName
  2876.                       //  );
  2877.                     }
  2878.                     
  2879.                     if ((fexist(iname)) || (fexist(iname2)) ) {
  2880.                       // vΘrifier existence de .whtt
  2881.                       strcpybuff(iname,CShellApp_app->end_path);
  2882.                       strcatbuff(iname,find.cFileName);
  2883.                       strcatbuff(iname,".whtt");
  2884.                       if (!fexist(iname)) {
  2885.                         FILE* fp=fopen(iname,"wb");
  2886.                         if (fp) fclose(fp);
  2887.                       }
  2888.                       
  2889.                     }
  2890.                   }
  2891.                 } else {    /* effacer .whtt qui ne pointent vers rien */
  2892.                   CString iname=CShellApp_app->end_path+find.cFileName;
  2893.                   if (iname.Right(5).CompareNoCase(".whtt")==0) {
  2894.                     CString rname=iname.Left(iname.GetLength()-5)+"\\index.html";
  2895.                     CString rname2=iname.Left(iname.GetLength()-5)+"\\hts-cache\\winprofile.ini";
  2896.                     if ( (!fexist((char*)LPCTSTR(rname))) && (!fexist((char*)LPCTSTR(rname2))) ) {
  2897.                       remove(iname);
  2898.                     }
  2899.                   }
  2900.                 }
  2901.         } while(FindNextFile(h,&find));
  2902.         FindClose(h);
  2903.         if (check_empty) {
  2904.           while(to_delete.GetLength()>0) {
  2905.             int pos=to_delete.Find('\n');
  2906.             if (pos) {
  2907.               CString path=to_delete.Left(pos);
  2908.               to_delete=to_delete.Mid(pos+1);
  2909.               CString str;
  2910.               str.Format(LANG_DELETEEMPTYCONF,path);
  2911.               if (AfxMessageBox(str,MB_OKCANCEL)==IDOK) {
  2912.                 /* Θliminer au besoin le .whtt */
  2913.                 DeleteFile(path+".whtt");
  2914.                 if (!RemoveEmptyDir(path))
  2915.                   AfxMessageBox(LANG_ERRORDEL);
  2916.               }
  2917.             } else
  2918.               to_delete="";
  2919.           }
  2920.         }
  2921.       }
  2922.       // Footer
  2923.       //fprintf(fpo,toptemplate_footer,
  2924.       //  "<!-- Mirror and index made by HTTrack Website Copier/"HTTRACK_VERSION" "HTTRACK_AFF_AUTHORS" -->"
  2925.       //  );
  2926.       //fclose(fpo);
  2927.     }
  2928.  
  2929.     TStamp t_end = mtime_local();
  2930.     TStamp l_opt = t_opt - t_start;
  2931.     TStamp l_build = t_build - t_opt;
  2932.     TStamp l_dir = t_end - t_build;
  2933.     //CString a;
  2934.     //a.Format("opt=%dms build=%dms dir=%dms", (int)l_opt, (int)l_build, (int)l_dir);
  2935.     //(void) AfxMessageBox(a, MB_OK);
  2936.   }
  2937.  
  2938.   
  2939.   /*
  2940.   if (toptemplate_header)
  2941.     freet(toptemplate_header);
  2942.   if (toptemplate_body)
  2943.     freet(toptemplate_body);
  2944.   if (toptemplate_footer)
  2945.     freet(toptemplate_footer);
  2946.   */
  2947. }
  2948.  
  2949. /*
  2950. -1 : error
  2951. 0 : directory is empty
  2952. 1 : empty directories inside
  2953. 2 : empty files inside
  2954. 3 : 1 + 2
  2955. 4 : not empty
  2956. */
  2957. int CheckDirInfo(CString path) {
  2958.   CWaitCursor wait;
  2959.   
  2960.   if (path.Right(1)!="\\")
  2961.     path+="\\";
  2962.   
  2963.   // Pour FindFirstFile/FindNextFile
  2964.   WIN32_FIND_DATA find;
  2965.   HANDLE h = FindFirstFile(path+"*.*",&find);
  2966.   
  2967.   // accessible
  2968.   if (h!=INVALID_HANDLE_VALUE) {
  2969.     int return_code=0;
  2970.     do {
  2971.       if (!(find.dwFileAttributes  & FILE_ATTRIBUTE_SYSTEM )) {
  2972.         if (strcmp(find.cFileName,"..")) {
  2973.           if (strcmp(find.cFileName,".")) {
  2974.             if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2975.               return_code|=1;
  2976.               int r=CheckDirInfo(path+find.cFileName);
  2977.               if (r==4)
  2978.                 return_code=4;
  2979.               else
  2980.                 return_code|=r;
  2981.             } else {
  2982.               return_code|=2;
  2983.               if ((find.nFileSizeLow) || (find.nFileSizeHigh))
  2984.                 return_code=4;
  2985.             }
  2986.           }
  2987.         }
  2988.       }
  2989.     } while(FindNextFile(h,&find) && !((return_code & 4)) );
  2990.     FindClose(h);
  2991.     return return_code;
  2992.   } else
  2993.     return -1;
  2994. }
  2995.  
  2996. /*
  2997. Remove Empty Dir
  2998. */
  2999. BOOL RemoveEmptyDir(CString path) {
  3000.   CWaitCursor wait;
  3001.   
  3002.   SetCurrentDirectory("C:\\");
  3003.   
  3004.   if (path.Right(1)!="\\")
  3005.     path+="\\";
  3006.   
  3007.   // Pour FindFirstFile/FindNextFile
  3008.   WIN32_FIND_DATA find;
  3009.   HANDLE h = FindFirstFile(path+"*.*",&find);
  3010.   
  3011.   // accessible
  3012.   if (h!=INVALID_HANDLE_VALUE) {
  3013.     do {
  3014.       if (!(find.dwFileAttributes  & FILE_ATTRIBUTE_SYSTEM )) {
  3015.         if (strcmp(find.cFileName,"..")) {
  3016.           if (strcmp(find.cFileName,".")) {
  3017.             if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  3018.               if (!RemoveEmptyDir(path+find.cFileName)) {
  3019.                 FindClose(h);
  3020.                 return 0;
  3021.               }
  3022.             } else {
  3023.               if ((!find.nFileSizeLow) && (!find.nFileSizeHigh))
  3024.                 if (!DeleteFile(path+find.cFileName)) {
  3025.                   FindClose(h);
  3026.                   return 0;
  3027.                 }
  3028.             }
  3029.           }
  3030.         }
  3031.       }
  3032.     } while(FindNextFile(h,&find));
  3033.     FindClose(h);
  3034.     
  3035.     SetCurrentDirectory("C:\\");
  3036.     return RemoveDirectory(path.Left(path.GetLength()-1));
  3037.   } else
  3038.     return 0;
  3039.   return TRUE;
  3040. }
  3041.